mardi 4 août 2015

Modal view doesn't respect Size Classes

I have two view controllers, each one loading their view from their own .xib file. I'm using size classes to display a different layout based on whether the device is in portrait and landscape mode.

The first view works fine: I can change orientations and the view is updated as in the size classes. However the second view doesn't work properly. If I present it while in portrait mode, changing to landscape doesn't update the view the way it should. However presenting it while in landscape mode works fine, and I can rotate back to portrait without issues.

I haven't done anything differently in the two .nib's, and I simply can't figure out why it's not working properly.

Have anyone experienced the same issue before, and know how I would go about fixing it?



via Chebli Mohamed

If-statement won't check NSArray

I am trying to create an if statement that checks to see if the selected cell is equal to an object in an array and if it is then it will set an NSURL accordingly. The table that I am referencing is from another view controller called PopOverViewController that I have created a delegate and used in the destinationViewController.

ViewController.m:

-(void) didLoadSelectedLayer:(NSString *)selectedLayer{
self.popOverArray = [[NSArray alloc] initWithObjects:@"Electric Radio", @"Electric Truck", @"Gas Radio", @"Gas Truck", @"Meter", @"Sewer Radio", @"Sewer Truck", @"Support Radio", @"Support Truck", @"Water Radio", @"Water Truck", @"Select All", nil];

if ([_popoverTableVC.myTable.indexPathForSelectedRow isEqual:@"Electric Radio"]) {
    _url = [NSURL URLWithString:@"http://somewebsite.com"];
}else{

}

I originally had a switch statement but since switch statements cannot use NSStrings I am confused on how to achieve the desired effect.

This is the PopOverViewController.h where I create the delegate:

#import <UIKit/UIKit.h>
#import <ArcGIS/ArcGIS.h>

#pragma mark - popoverTableViewControllerDelegate

@protocol popOverTableViewControllerDelegate <NSObject>
@required
-(void) didLoadSelectedLayer:(NSString *)selectedLayer;


@end

@interface PopOverTableViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate>
{
AGSFeatureLayer *popOverLayer;

IBOutlet UITableView *myTable;


}
@property (nonatomic, strong)IBOutlet UITableView *myTable;
@property (nonatomic, strong) NSArray *popOverArray;
@property (nonatomic,strong) id<popOverTableViewControllerDelegate> delegate;
//-(void)didSelectObject:(UITableView *)tableView :(NSInteger *)key;
@end

This is the PopOverViewController.m:

#import "PopOverTableViewController.h"
#import "ViewController.h"

#pragma mark - PopOverTableViewControler

@interface PopOverTableViewController ()
{
    NSURL *_url;
    ViewController *_ViewController;
}

@end

@implementation PopOverTableViewController
@synthesize delegate;

-(void)viewDidLoad
{
    [super viewDidLoad];
    self.popOverArray = [[NSArray alloc] initWithObjects:@"Electric Radio", @"Electric Truck", @"Gas Radio", @"Gas Truck", @"Meter", @"Sewer Radio", @"Sewer Truck", @"Support Radio", @"Support Truck", @"Water Radio", @"Water Truck", @"Select All", nil];
    [self.tableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    // Return the number of rows in the section.
    return [self.popOverArray count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 1;
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
        NSString *selectedLayer = [_popOverArray objectAtIndex: indexPath.row];
        [self.delegate didLoadSelectedLayer:selectedLayer];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier =@"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    cell.textLabel.text = [self.popOverArray objectAtIndex:indexPath.row];
    return cell;
}


@end



via Chebli Mohamed

Transfering code from cellForItemAtIndexPath to a CollectionViewCell (Parse Back-End)

I'm using Parse as the database for my app. I want to create a CollectionViewCell and transfer my code there, instead of having it inside the View Controller's cellForItemAtIndexPath. How do I do this?

Thanks.

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"productCell";

    ProductCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

    PFObject *product = [self.products objectAtIndex:indexPath.row];

    NSString *price = [NSString stringWithFormat:@"$%@.00", product[@"price"]];

    cell.price.text = price;

    PFFile *userImageFile = product[@"firstThumbnailFile"];
    [userImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
        if (!error) {
            UIImage *thumbnailImage = [UIImage imageWithData:imageData];
            UIImageView *thumbnailImageView = [[UIImageView alloc] initWithImage:thumbnailImage];

            cell.image.image = thumbnailImageView.image;
        }
    }];

    return cell;
}

Cell.h

@interface ProductCell : UICollectionViewCell

@property (nonatomic, weak) IBOutlet UIImageView *image;
@property (nonatomic, weak) IBOutlet UILabel *price;

@end



via Chebli Mohamed

how to send array value to another class

I have problem with send array value to another class. I'm sure that it's obvious but I don't have any idea to do this.

I'll be glad for any example code.

Problem: class1 send text from searchBar to class2. In class2 I get a data from www[JSONModel] and generate an array. My problem is how to send value this array to class1 and make reloadData in tableView.

To send data from class1 to class2 I use delegate method [SearchTextDelegate] I tried to make next delegate to send data from class2 to class1 but it doesn't work.

Thanks in advance.

my class1.m:

#pragma mark - searchBar
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)text {

    self.mySearchText = [NSString stringWithFormat:@"%@", text];
    NSLog(@"mySearchText: %@", self.mySearchText);

    if (text != 0) {

        APIClient *wskAPI = [[APIClient alloc]init];
        wskAPI.delegate = self;
        wskAPI.searchText = self.mySearchText;
        [wskAPI createSearchString];
    }
    [self.tableView reloadData];
}

#pragma mark - Sample protocol delegate
-(void)searchProcessCompleted {

    [self.tableView reloadData];
}

my class2.h [APIClient.h]:

#import <Foundation/Foundation.h>
#import "ITunesResultModel.h"

@protocol SearchTextDelegate <NSObject>

-(void)searchProcessCompleted;

@end

@interface APIClient : NSObject

@property (strong, nonatomic) id delegate;
@property (assign) id <SearchTextDelegate> stringDelegate;

@property (strong, nonatomic) NSString *searchString;
@property (strong, nonatomic) NSString *searchText;

@property (strong, nonatomic) ITunesResultModel *iTunesModel;
@property (strong, nonatomic) NSArray *resultArray;

-(void)createSearchString;

@end

my class2.m [APIClient.m]:

#import "APIClient.h"
#import "ITunesResultModel.h"
#import "JSONModelLib.h"
#import "class1.h"

@implementation APIClient

static NSString * const ITunesOnlineURLString = @"http://ift.tt/1CToUkG";

-(void)createSearchString {

    NSLog(@"searchTextAPI: %@", self.searchText);

    self.searchString = [NSString stringWithFormat:@"http://ift.tt/1j7O455", self.searchText];

    //fetch the feed
    self.iTunesModel = [[ITunesResultModel alloc] initFromURLWithString:self.searchString
                                         completion:^(JSONModel *model, JSONModelError *err) {

                                             //json fetched
                                             //NSLog(@"result: %@", self.iTunesModel.results);

                                         }];  
}

@end



via Chebli Mohamed

Swift ios is it bad to have an embedded table view

I wonder if there is any downside in having an embedded table view?

I have a navigation controller VC that leads to another VC which is my apps "main/root" VC.

Inside that VC I have a container view which holds an table view.

Is this a bad setup? The table view then has more segues leading to other VC's



via Chebli Mohamed

Three-Finger UIPanGestureRecognizer doesn't work when Accessibility -> Zoom is on in "Settings App"

So, I have this code which basically creates a UIPanGestureRecognizer and adds it to the view. In the target method I am just printing the number of touches. It works fine under normal circumstance; and print correct number of touches.

But if "Settings -> Accessibility -> Zoom" is turned On, then it fails for 3-finger touch.

- (void)viewDidLoad
{
  [super viewDidLoad];
  UIPanGestureRecognizer *tempGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleTempGesture:)];
  tempGesture.minimumNumberOfTouches = 1;
  tempGesture.maximumNumberOfTouches = 3;
  [tempGesture setDelegate:self];
  [self.view addGestureRecognizer:tempGesture];
}

- (void)handleTempGesture:(UIGestureRecognizer *)recognizer
{
  NSUInteger touches = recognizer.numberOfTouches;
  NSLog(@"Touches Count: %i", (int)touches);
}

Is there a way around it i.e. without having to turn off the zoom.

PS: Even 3-Finger UITapGestureRecognizer doesn't work.



via Chebli Mohamed

iOS: CoreLocation Speed and Heading not working on physical device

I have some code that works 100% fine in the simulator. It shows heading and speed 100% correct; however; the second I run it on a proper device the speed and heading results are -1.

Anybody any ideas as to why? Or how to try and troubleshoot this problem?



via Chebli Mohamed