【发布时间】:2011-03-08 03:10:17
【问题描述】:
我在 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 = [[[UITableViewCell 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
问题是当我单击一个单元格时,它会突出显示该单元格,但不会显示警报。有什么我想念的吗?在 FirstView 内部,我有一个 tableview,tableview 查看 tableview 对象,该对象的类设置为 TaskTableController。
【问题讨论】:
-
您似乎没有在 FirstView 中分配 UITableView 的“委托”,您只有附加“数据源”,
标签: iphone objective-c ios uitableview uitabbarcontroller