I have the following code in a UITableViewController:
#import "TaskTableController.h"
@implementation TaskTableController
- (void)viewDidLoad {
theArray = [[NSArray alloc] initWithObjects:@"Apple",@"Pineapple",@"Banana",nil];
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [theArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITab开发者_运维百科leViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [theArray objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Selected a row" message:[theArray objectAtIndex:indexPath.row] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
- (void)dealloc {
[theArray release];
[super dealloc];
}
@end
The problem is when I click on a cell, it highlights the cell but does not ever show the alert. Is there something that I am missing? Inside FirstView I have a tableview the tableview looks at the tableview object that's class is set to TaskTableController.
I think you forget to set delegate UITableViewDelegate with FileOwner.
精彩评论