Reputation: 1778
Hi I am using storyborad to create UI in IOS.eveything is fine but its not navigating to next view controller.I am using code as below
[self performSegueWithIdentifier:@"identifier" sender:self]; and
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:@"identifier"]){
ViewController *destVC =(ViewController *) [segue destinationViewController];
}
My Tableview delegates
-(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];
}
Please correct me where am doing wrong. P.S: I have connectd View Controller properly with segueIdentifier in story board and changed class name of VC to my Class.
Upvotes: 0
Views: 505
Reputation:
This code will be really useful to you to change the view controller using Storyboard ID.
For example - There were 2 view Controllers named FirstViewController and SecondViewController respectively. If you want to move from FirstViewController to SecondViewController there is a simple Code using Storyboard ID.
Step 1 :-
Enter the StoryBoard ID for both the ViewControllers
Step 2 :-
Write a code in FirstViewController -
let secondVC = self.storyboard?.instantiateViewControllerWithIdentifier("SecondViewController") as! SecondViewController
self.navigationController?.pushViewController(secondVC, animated: true)
Upvotes: 1
Reputation: 1061
Your code in performSegueWithIdentifier actually does nothing. So to show the destination scene you must wire it in Interface Builder like so:
Then it should look like this and should work:
Hope this helps.
Upvotes: 0