ios - UITableView 点击一个项目打开一个新的屏幕/ View /事件

标签 ios objective-c uitableview

我有一个 TableView (HomeViewController),由以下项目组成:

  1. 地点

  2. 报告

  3. 设置

我将这些项目作为单独的文件(LocationViewController、ReportingView Controller 和 Setting ViewController)。现在,如果用户单击位置,应该打开一个新的屏幕/事件/ View ,其余项目也一样。 有人可以帮忙吗。我的代码是:

    #import "HomePageController.h"  @implementation HomePageController
    @synthesize menuList, table;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void)viewDidLoad
 {

    menuList=[[NSMutableArray alloc] initWithObjects:

              [NSArray arrayWithObjects:@"LOCATIONS",nil],

              [NSArray arrayWithObjects:@"REPORTING",nil], 

              [NSArray arrayWithObjects:@"SETTINGS",nil],

              [NSArray arrayWithObjects:@"PASSWORD",nil],

              [NSArray arrayWithObjects:@"HELP",nil],

              [NSArray arrayWithObjects:@"ABOUT",nil],

              [NSArray arrayWithObjects:@"SHARE",nil],
              nil];
    [self.navigationController setNavigationBarHidden:NO];  
    self.navigationController.navigationBar.tintColor=[UIColor blackColor]; 
    self.navigationController.navigationBar.barStyle=UIBarStyleBlackTranslucent;    
    self.title=@"CoinRead";     
    [table reloadData];
    [super viewDidLoad];
}

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)theTableView{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}

- (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section{
    return menuList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"CellIdentifier";

    UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil){

        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero] autorelease];
    }

    cell.highlighted=NO;

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    NSArray *rowArray = [menuList objectAtIndex:indexPath.row];

    UILabel *nameLabel = [[[UILabel alloc] initWithFrame:CGRectMake(15, 8, 200, 20)]autorelease];

    nameLabel.text = [NSString stringWithFormat:@"%@",[rowArray objectAtIndex:0]];

    nameLabel.backgroundColor = [UIColor clearColor];

    nameLabel.shadowColor=[UIColor whiteColor];

    nameLabel.shadowOffset=CGSizeMake(0.0, 0.5);

    nameLabel.textColor = RGB(0,0,0);

    [nameLabel setFont:[UIFont boldSystemFontOfSize:16.0f]];

    [cell.contentView addSubview:nameLabel];

    return cell;
}

最佳答案

实现UITableViewDelegate下面的方法来获取选择事件

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

关于ios - UITableView 点击一个项目打开一个新的屏幕/ View /事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5457675/

相关文章:

ios - 无法创建配置文件

ios - NSUserDefaults 不会在导航时保存

ios - 在 ios 中使用 XmppFrameWork 进行文件传输

objective-c - 如何使用 NSXMLParser 解析包含 & 符号的字符串?

objective-c - 调试 iOS 应用程序时如何在 Xcode 控制台中打印 unsigned char?

objective-c - 似乎无法使用 ARC 从 NSString* 转换为 CFString*

ios - 使用给定路径剪切图像

ios - 在 TableView 中插入行

ios - 为 iPhone 和 iPad 布局静态表格单元格

ios - 当我在 iOS 中滚动 UITableView 时,cellForRowAtIndexPath 无法正确显示单元格