2012-02-17 4 views
0

テーブルビューを作成してラベルを追加して表示したので、各セルにボタンが必要です新しい画面にリダイレクトします。 次は、私は上記のコードで間違ったつもりだ私はリダイレクトしようとしていますコード、ボタンの新しい画面にリダイレクトする方法対象のcでテーブルビューをクリックする

- (void)viewDidLoad 
{ 
    vendorsArray = [CommonUserDetails sharedUserDetails].mVendorDictionary; 
    NSLog(@"vendorsArray is %@ \n count is %d",vendorsArray,[vendorsArray count]); 

    loTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 43, 320, 400) style:UITableViewStylePlain]; 
    [loTableView setBackgroundColor:[UIColor whiteColor]]; 

    loTableView.delegate = self; 
    loTableView.dataSource = self; 
    loTableView.separatorColor = [UIColor grayColor]; 
    [self.view addSubview:loTableView]; 

    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"]; 
    if (cell == nil) 
    { 
     cell = [self tableviewCellWithReuseIdentifier:@"myCell"]; 

    } 
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

    [self configureCell:cell forIndexPath:indexPath]; 
    //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    return cell; 
} 

#define L1_TAG 1 
#define L2_TAG 2 
#define L3_TAG 3 
#define L4_TAG 4 

- (UITableViewCell *)tableviewCellWithReuseIdentifier:(NSString *)identifier 
{ 
    UITableViewCell* cell = [[UITableViewCell alloc]initWithFrame:CGRectMake(0, 0, 320, 100)reuseIdentifier:identifier]; 

    UILabel* l1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 290, 30)]; 
    [l1 setBackgroundColor:[UIColor clearColor]]; 
    [l1 setFont:[UIFont systemFontOfSize:14]]; 
    // [l1 setTextColor:[UIColor blackColor]]; 
    l1.textColor = [UIColor colorWithRed:153/(CGFloat)255 green:51/(CGFloat)255 blue:0 alpha:1.0]; 
    [l1 setAdjustsFontSizeToFitWidth:YES]; 
    [l1 setTextAlignment:UITextAlignmentRight]; 
    l1.tag = L1_TAG; 
    [cell.contentView addSubview:l1]; 


    UILabel* l2 = [[UILabel alloc] initWithFrame:CGRectMake(5, 20 , 300, 30)]; 
    [l2 setBackgroundColor:[UIColor clearColor]]; 
    l2.font = [UIFont boldSystemFontOfSize:14]; 
    l2.textColor = [UIColor blackColor]; 
    //l2.textColor = [UIColor colorWithRed:102/(CGFloat)255 green:102/(CGFloat)255 blue:153/(CGFloat)255 alpha:1.0]; 
    l2.tag = L2_TAG; 
    [l2 setTextAlignment:UITextAlignmentLeft]; 
    [cell.contentView addSubview:l2]; 

    UILabel* l3 = [[UILabel alloc] initWithFrame:CGRectMake(5, 40, 190, 30)]; 
    [l3 setBackgroundColor:[UIColor clearColor]]; 
    [l3 setFont:[UIFont systemFontOfSize:14]]; 
    [l3 setTextColor:[UIColor grayColor]]; 
    // l3.textColor = [UIColor colorWithRed:102/(CGFloat)255 green:102/(CGFloat)255 blue:0/(CGFloat)255 alpha:1.0]; 
    [l3 setAdjustsFontSizeToFitWidth:YES]; 
    l3.tag = L3_TAG; 
    [cell.contentView addSubview:l3]; 

    UILabel* l4 = [[UILabel alloc] initWithFrame:CGRectMake(5, 60, 190, 30)]; 
    [l4 setBackgroundColor:[UIColor clearColor]]; 
    [l4 setFont:[UIFont systemFontOfSize:14]]; 
    [l4 setTextColor:[UIColor grayColor]]; 
    //l4.textColor = [UIColor colorWithRed:0/(CGFloat)255 green:51/(CGFloat)255 blue:0/(CGFloat)255 alpha:1.0]; 
    [l4 setAdjustsFontSizeToFitWidth:YES]; 
    l4.tag = L4_TAG; 
    [cell.contentView addSubview:l4]; 

     UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     button.frame = CGRectMake(150, 60, 70, 30); 
     [button setTitle:@"Pay" forState:UIControlStateNormal]; 
     [cell.contentView addSubview:button]; 
    [button addTarget:self action:@selector(payButton) 
      forControlEvents:UIControlEventTouchUpInside]; 


    return cell; 
} 

- (void)configureCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath 
{ 

    UILabel *myl1 = (UILabel*)[cell viewWithTag:L1_TAG]; 
    UILabel *myl2 = (UILabel*)[cell viewWithTag:L2_TAG];  
    UILabel *myl3 = (UILabel*)[cell viewWithTag:L3_TAG]; 
    UILabel *myl4 = (UILabel*)[cell viewWithTag:L4_TAG]; 

    NSDictionary *dictionary = [vendorsArray objectAtIndex:indexPath.row]; 
    myl1.text= [NSString stringWithFormat:@"INo:%@",[dictionary objectForKey:@"iNo"]]; 
    myl2.text=[dictionary objectForKey:@"vendorName"]; 
    myl3.text= [NSString stringWithFormat:@"Amount:%@",[dictionary objectForKey:@"amount"]]; 
    myl4.text= [NSString stringWithFormat:@"DDate:%@",[dictionary objectForKey:@"dDate"]]; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section 
{ 
    NSLog(@"count is %d",[vendorsArray count]); 
    return [vendorsArray count]; 
} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{ 
    return @"Payables"; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 100; 
} 
-(IBAction) payButton{ 

    PayDescriptionController *mPayDescriptionController = [[PayDescriptionController alloc]initWithNibName:@"PayDescriptionController" bundle:nil]; 
    mPayDescriptionController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    [self.navigationController presentModalViewController:mPayDescriptionController animated:YES]; 
} 

です。

+0

あなたのコードではどうなりますか? –

+0

新しい画面にリダイレクトしたボタン、つまりpayDescriptionControllerにリダイレクトされたボタンをクリックすると、テーブルビューにあるボタンのpayButtonが呼び出されますが、ボタンをクリックするとそのページが表示されません。 – shasha

+0

あなたは 'payButton'を呼んでいますか?あなたは 'NSLog'またはブレークポイントでそれをチェックしましたか? –

答えて

0

は、それが次のビューに移動するかしない参照

[self.navigationController pushViewController:mPayDescriptionController animated:YES]; 

、これを試してみてください!!そうでない場合は、あなたのオブジェクトの1つがnullである可能性があります。

関連する問題