2014-05-23 70 views
2

我想從一個表視圖單元傳遞數據到下一個UIViewController。我使用的導航器也,但是當我點擊單元格,然後把它給錯誤: -- [UIViewController setSelectedRowTitle:]:無法識別的選擇發送到實例0x13fab360

-[UIViewController setSelectedRowTitle:]: unrecognized selector sent to instance 0x13fab360 

我用它去下一個數據是我prepareForSegue代碼: -

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [NearBy_PlacesArray count]; 
} 


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *TableIdentifire = @"NearMe"; 

    NearByTableViewCell *cell = (NearByTableViewCell*)[self.tableView dequeueReusableCellWithIdentifier:TableIdentifire]; 

    if (cell == nil) 
    { 
     cell = [[NearByTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableIdentifire]; 

    } 

    NearByPlace *nearBy = [NearBy_PlacesArray objectAtIndex:indexPath.row]; 

    cell.NearBy_Thumbnail_Image.image = [UIImage imageNamed:nearBy.NearByImageName]; 
    cell.NearBy_TitleLabel.text = nearBy.NearByPlaceName; 
    cell.NearBy_NoLabel.text = nearBy.NearByPlace_no; 


    return cell; 
} 
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([segue.identifier isEqualToString:@"ShowNearByPlaces"]) 
    { 


     NSIndexPath *indexPath = nil; 
     NearByPlace *nearPlace = nil; 

      indexPath = [self.tableView indexPathForSelectedRow]; 
      nearPlace = [NearBy_PlacesArray objectAtIndex:indexPath.row]; 

     NSLog(@"indexPath-- %@ \n" , indexPath); 
     NSLog(@"recipe-- %@ \n " , nearPlace); 


     nearByPlaceDetail_ViewController *destViewController = segue.destinationViewController; 

     destViewController.SelectedRowTitle = nearPlace; 
    } 
} 

回答

1

Mantosh,你可以簡單地這樣做:

  • (UITableViewCell的*)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath

    靜態NSString * aStrIdentifier = @「cell」; UITableViewCell * aCell = [tableView dequeueReusableCellWithIdentifier:aStrIdentifier];

    UILabel *aLblPlaceName=(UILabel*)[aCell viewWithTag:1]; 
    aLblPlaceName.text=[NSString stringWithFormat:@"%@", [arrPlaces objectAtIndex:indexPath.row]]; 
    
    return aCell; 
    

    }

  • (無效)的tableView:(UITableView的*)的tableView didSelectRowAtIndexPath方法:(NSIndexPath *)indexPath

    { strStoreValue = [NSString的stringWithFormat:@ 「%@」,[arrPlaces objectAtIndex:indexPath.row]]; [self performSegueWithIdentifier:@「detailViewSegue」sender:self]; }

  • (無效)prepareForSegue:(UIStoryboardSegue *)賽格瑞發件人:(ID)發送方

    { DetailViewController * aObjDetailVC = segue.destinationViewController; aObjDetailVC.strPlace = strStoreValue; }

相關問題