您好我正在使用storyborad在IOS中创建UI。一切正常,但它没有导航到下一个视图控制器。我使用的代码如下
[self performSegueWithIdentifier:@"identifier" sender:self]; and
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:@"identifier"]){
ViewController *destVC =(ViewController *) [segue destinationViewController];
}
我的Tableview委托
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"InfoCell";
HMSForumInfoCell *cell = (InfoCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"InfoCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
NSLog(@"Cell created");
}
NSDictionary *detailsDic = [_filteredListOfForums objectAtIndex:indexPath.row];
[cell.headLinesLabel setText:[detailsDic objectForKey:kTopic]];
// Adding underlined Colored text using NSMutableAttributedString
NSMutableAttributedString *commentString = [[NSMutableAttributedString alloc] initWithString:[detailsDic objectForKey:kCreatedby]];
UIColor* textColor = [UIColor colorWithRed:255.0f/255.0f green:198.0f/255.0f blue:0.0f/255.0f alpha:1.0f];
[commentString setAttributes:@{NSForegroundColorAttributeName:textColor,NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]} range:NSMakeRange(0,[commentString length])];
[cell.nameButton setAttributedTitle:commentString forState:UIControlStateNormal];
// [cell.nameButton addTarget:self action:@selector(replyButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[cell.nameButton addTarget:self action:@selector(namebuttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[cell.replyButton addTarget:self action:@selector(replyButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
- (void)replyButtonPressed:(id)sender {
[self performSegueWithIdentifier:@"id1" sender:self];
}
- (void)namebuttonPressed:(id)sender {
[self performSegueWithIdentifier:@"id2" sender:self];
}
请纠正我在哪里做错了。 P.S:我已将故事板中的segueIdentifier与View Controller正确连接,并将VC的类名更改为我的班级。
答案 0 :(得分:1)
此代码对使用Storyboard ID更改视图控制器非常有用。
例如 - 有两个视图控制器分别命名为FirstViewController和SecondViewController。 如果你想从FirstViewController转到SecondViewController,那么使用Storyboard ID就有一个简单的代码。
第1步: -
输入ViewControllers
的StoryBoard ID第2步: -
在FirstViewController中编写代码 -
let secondVC = self.storyboard?.instantiateViewControllerWithIdentifier("SecondViewController") as! SecondViewController
self.navigationController?.pushViewController(secondVC, animated: true)
答案 1 :(得分:0)
您在performSegueWithIdentifier中的代码实际上什么都不做。因此,为了显示目标场景,您必须在Interface Builder中连接它,如下所示:
然后它应该看起来像这样,应该可以工作:
希望这有帮助。