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
Aucun commentaire:
Enregistrer un commentaire