我在 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 查看其类设置为 TaskTableController 的 TableView 对象。
最佳答案
我认为您忘记使用 FileOwner 设置委托(delegate) UITableViewDelegate。
关于iphone - TableView 警报不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5227899/