开发者

Table Views Pushing to New Views XIB's

开发者 https://www.devze.com 2023-02-17 20:23 出处:网络
I have created a table view that pulls its cells from an array. Each cell needs to push to a different view... and I cannot find the value of the tapped cell. It needs a conditional statement but wi

I have created a table view that pulls its cells from an array.

Each cell needs to push to a different view... and I cannot find the value of the tapped cell. It needs a conditional statement but without the value i cannot push the view :(

开发者_Python百科below is the snippet of my didSelectRowAtIndexPath

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.

if(){

SendSms *detailViewController = [[SendSms alloc] initWithNibName:@"SendSms" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}

}

You will see the If statement is blank... I need the value of the column pushed to push to another view controller.

Please help! Thanks


I'll answer my own question for those who may be searching it out since i just worked it out :)

use:

if([InsertYourArrayOfDataHere objectAtIndex:indexPath.row] == @"StringInArray")

Hope that might help someone with the same problem


Even after Jonathan's answer I recommend to use this, It would be better to use

if([[InsertYourArrayOfDataHere objectAtIndex:indexPath.row] isEqualToString: @"StringInArray"]) {
//Your Code goes here.
}

If you are comparing string you should use isEqualToString method.


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//you willget alldetail of cell here.

if(){

SendSms *detailViewController = [[SendSms alloc] initWithNibName:@"SendSms" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}


you can find the value of the tapped cell like

indexpath.row,

when user will touch any cell values the indexpath.row will provide you a number then you can perform some actions like

if(indexpath.row == 0)

{

//here create the object for the view1 where you want to navigate

//show view 1

}

else 
{

//show view 2

}

Hope this will solve your problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消