iphone - TableView 警报不显示

标签 iphone objective-c ios uitableview uitabbarcontroller

我在 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/

相关文章:

iphone - 在 iOS 中使用 Core Data 进行数据加密

ios - 从另一个选项卡返回到根 Controller

ios - 针对 iOS 11.0 但仍收到警告 : is only available on iOS 10. 0 或更新版本

ios - 在 UIPageViewControllers 中预加载所有 UIViewControllers (Swift)

ios - 如何以针对不同尺寸显示器的模式排列多个 UIView

iphone - 服务器如何验证 iPhone 应用程序(代码,而不是用户)?

ios - 使用其标签将图像添加到 UIImageView

objective-c - 这两种 dealloc 方法有什么区别?

ios - Swift 3 中的 PBEWithMD5AndDES 加密

ios - 在 Objective-C 的 UIImage 的透明区域上屏蔽背景颜色