在Switch内部调用UIViewController

时间:2014-02-19 06:27:45

标签: ios objective-c uitableview uiviewcontroller nsdictionary

您好我来自didSelectRowAtIndexPath的代码,问题是我无法通过调用switch

来使用UIViewController案例
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];

TaskList *account = nil;
if (indexPath.section == 0) {
    account = [_forCheckerList objectAtIndex:indexPath.row];
}else if (indexPath.section == 1) {
    account = [_forApprovalList objectAtIndex:indexPath.row];
}else{
    account = [_forVerificationList objectAtIndex:indexPath.row];
}

NSDictionary *funcColors = (NSDictionary*)[dict objectForKey:@"funcTags"];
int tag = [[funcColors objectForKey:[account funcCd]] intValue];
FundTransferOwnViewController *sc = [[FundTransferOwnViewController alloc]init];
[self.navigationController pushViewController:sc animated:YES];
switch (tag) {
    case 10: //aca
        AutoCreditViewController *sc = [[AutoCreditViewController alloc]init];
        [self.navigationController pushViewController:sc animated:YES];
        break;
    default:
        break;
}}

在案例10中,我正在呼叫AutoCreditViewController,它总是会提示一个红色感叹号,上面写着“预期表达”。

3 个答案:

答案 0 :(得分:1)

将开关案例嵌入 大括号{}

switch (tag) 
{
   case 10: 
   {
      AutoCreditViewController *sc = [[AutoCreditViewController alloc]init];
      [self.navigationController pushViewController:sc animated:YES];
      break;
    }
   default:
      break;
 }

答案 1 :(得分:0)

在开关中初始化新对象时,需要添加花括号{。 所以你的开关应该是这样的:

switch (tag) {
    case 10:
        {
            AutoCreditViewController *sc = [[AutoCreditViewController alloc]init];
            [self.navigationController pushViewController:sc animated:YES];
            break;
        }
    default:
        break;
}}

答案 2 :(得分:0)

你们两个“sc”对象都是同一个名字,但是差异类别,保持两者不同,然后看看会有什么好处。