点击一个项目打开一个新的屏幕

点击一个项目打开一个新的屏幕

本文介绍了UITableView 点击一个项目打开一个新的屏幕/视图/活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a table view(HomeViewController) consisting of items as:

  1. 位置

报告

设置

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

I am having these items as separate files(LocationViewController,ReportingView Controller and Setting ViewController).Now if user clicks on location a new screen/activity/view should be open and same for rest items.Can some one please help.my code is as:

    #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的方法来获取选择事件

Implement below method of UITableViewDelegate to get the selection event

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

这篇关于UITableView 点击一个项目打开一个新的屏幕/视图/活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:53