2012-08-03 19 views
25

मैं आईट्यून्स यू स्टैनफोर्ड आईओएस कक्षा ले रहा हूं और थोड़ा फ़्लिकर ऐप बनाने के लिए असाइनमेंट में से एक पर काम कर रहा हूं। मैं एक त्रुटि है कि मैं डिबग जिसमेंUITableViewController में दावा विफलता

* अभिकथन विफलता के रूप में आता करने में सक्षम हो नहीं कर पा रहे हो रही है - [_configureCellForDisplay UITableView: forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2280.1/UITableView। मी: 5336 2012-08-03 10: 59: 24.596 असाइनमेंट 4 [4611: C07] (शून्य) libC++ abi.dylib: बुलाया समाप्त सवाल में tableviewcontroller के लिए एक अपवाद

मेरे कोड फेंकने :

#import "PlacesPhotosTableViewController.h" 

@interface PlacesPhotosTableViewController() 
@property (nonatomic) NSDictionary *placeToDisplay; 
@property (nonatomic) NSArray *photosInPlace; 
@end 

@implementation PlacesPhotosTableViewController 
@synthesize placeToDisplay = _placeToDisplay; 
@synthesize photosInPlace = _photosInPlace; 

- (id)initWithStyle:(UITableViewStyle)style 
{ 
    self = [super initWithStyle:style]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (id)init 
{ 
    self = [super init]; 

    return self; 
} 

- (id)initWithPlace:(NSDictionary *)place 
{ 
    self = [self init]; 
    if (self) 
    { 
     self.placeToDisplay = place; 
    } 

    return self; 
} 

- (NSArray *)photosInPlace 
{ 
    if (_photosInPlace == nil) 
    { 
     _photosInPlace = [FlickrFetcher photosInPlace:self.placeToDisplay maxResults:50]; 
    } 

    return _photosInPlace; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    NSLog([self.placeToDisplay valueForKeyPath:@"description._content"]); 

    // Uncomment the following line to preserve selection between presentations. 
    // self.clearsSelectionOnViewWillAppear = NO; 

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    // self.navigationItem.rightBarButtonItem = self.editButtonItem; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

#pragma mark - Table view data source 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
#warning Incomplete method implementation. 
    // Return the number of rows in the section. 
    return [self.photosInPlace count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Photos"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    NSString *string = [[self.photosInPlace objectAtIndex:indexPath.row] valueForKeyPath:@"description._content"]; 

    cell.textLabel.text = string; 

    return cell; 
} 
+0

अपने सेल पहचानकर्ता को भी पंजीकृत करें देखें। http://stackoverflow.com/questions/15813498/custom-table-cell-reuse-dequeue – Temporaneous

उत्तर

65

CellIdentifier मैं शर्त लगाता हूं कि cellForRowAtIndexPathnil लौटा रहा है।

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

    /** NOTE: This method can return nil so you need to account for that in code */ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    // NOTE: Add some code like this to create a new cell if there are none to reuse 
    if(cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

    } 

    NSString *string = [[self.photosInPlace objectAtIndex:indexPath.row]  valueForKeyPath:@"description._content"]; 

    cell.textLabel.text = string; 

    return cell; 
} 

शायद यही कारण है [UITableView _configureCellForDisplay:forIndexPath:] विफल हो रहा है ... क्योंकि cellForRowAtIndexPath एक शून्य मान लौट रहा है और फिर configureCellForDisplay एक UITableViewCell उम्मीद कर रहा है यही कारण है कि।

+0

यही काम किया! जिज्ञासा से बाहर, एक सेल कभी शून्य क्यों होगा? – gsapienza

+0

एक साधारण उदाहरण तब होगा जब यह पहले सेल को प्रस्तुत करने का प्रयास करता है। कोई UITableViewCells नहीं बनाया गया है इसलिए पुन: उपयोग करने के लिए कोई भी नहीं है। – jerrylroberts

+1

विचित्र विचार है कि मुझे दूसरी तालिका के लिए ऐसा करने की ज़रूरत नहीं है मेरे पास – gsapienza

2

यहाँ

static NSString *CellIdentifier = @"Photos"; 

इस लाइन क्या यह मैच अपने स्टोरीबोर्ड में सेल पहचानकर्ता? मैंने पाया कि यह मिलान मेरे लिए समस्या का कारण नहीं था!

0

आप विधि

में सेल का निर्माण नहीं कर रहे हैं
tableView:cellForRowAtIndexPath: 

आप केवल इस विधि जो nil शुरू में रिटर्न से सेल पुन: उपयोग।

आपको अपनी विधि में दिए गए कोड के नीचे सेल बनाना होगा।

if(cell==nil){ 

    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
reuseIdentifier:CellIdentifier] autorelease]; 

} 
2

मैं एक ही समस्या का सामना करना पड़ा और इसे हल कारण मैं अब

return cell; 

जोड़ने के लिए अपने संकल्प लिया भूल गया।

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    if(tableView==notiTblView){ 

     NSLog(@"TABLE NEW"); 

     static NSString *cellIdentifier = @"MenuCell"; 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
     UIImageView *imageview; 
     UILabel *label; 
     UILabel *lblDetail; 

     if(cell == nil) 
     { 

      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
      imageview=[[UIImageView alloc]initWithFrame:CGRectMake(8, 3,30, 37)]; 
      label=[[UILabel alloc]initWithFrame:CGRectMake(70, 10, 100, 20)]; 
      lblDetail=[[UILabel alloc]initWithFrame:CGRectMake(70, 35, 100, 30)]; 
      lblDetail.numberOfLines=3; 

      imageview.tag=100; 
      label.tag=101; 
      lblDetail.tag=102; 

      label.textColor=[UIColor blackColor]; 
      label.font=[UIFont systemFontOfSize:15]; 
      label.backgroundColor=[UIColor clearColor]; 

      lblDetail.textColor=[UIColor grayColor]; 
      lblDetail.font=[UIFont systemFontOfSize:13]; 
      lblDetail.backgroundColor=[UIColor clearColor]; 


      [cell.contentView addSubview:imageview]; 
      [cell.contentView addSubview:label]; 
      [cell.contentView addSubview:lblDetail]; 

     } 

     cell.selectionStyle=UITableViewCellSelectionStyleNone; 
     UIImageView *img=(UIImageView *)[cell.contentView viewWithTag:100]; 
     UILabel *lbl=(UILabel *)[cell.contentView viewWithTag:101]; 

     NSString * stirngId = [NSString stringWithFormat:@"%@",[[notificationARRAY objectAtIndex:indexPath.row]objectForKey:@"photoID"]]; 

     if ([dicImages_msg valueForKey:[[notificationARRAY objectAtIndex:indexPath.row] valueForKey:@"productName"]]) { 

      img.image=[dicImages_msg valueForKey:[[notificationARRAY objectAtIndex:indexPath.row] valueForKey:@"productName"]]; 

     } 
     else 
     { 
      if (!isDragging_msg && !isDecliring_msg) 
      { 
       [dicImages_msg setObject:[UIImage imageNamed:@"timthumb.jpg"] forKey:[[notificationARRAY objectAtIndex:indexPath.row] valueForKey:@"productName"]]; 
       [self performSelectorInBackground:@selector(download_Noti_image:) withObject:indexPath]; 
      } 
      else 
      { 
       img.image=[UIImage imageNamed:@"timthumb.jpg"]; 
      } 
     } 

     lbl.text=[[notificationARRAY objectAtIndex:indexPath.row] objectForKey:@"memberName"]; 
     lbl.text=[[notificationARRAY objectAtIndex:indexPath.row] objectForKey:@"memberName"]; 

     return cell; 

     /* static NSString *MyIdentifier = @"MyIdentifier"; 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
     if (cell == nil) { 
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] ; 
      cell.selectionStyle=UITableViewCellSelectionStyleNone; 
      } 
     cell.textLabel.text=[[notificationARRAY objectAtIndex:indexPath.row] objectForKey:@"memberName"]; 
     return cell;*/ 

    }else{ 
     static NSString *cellIdentifier = @"MenuCell"; 
     TblCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
     if (cell==nil) { 
      cell = [[TblCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
      } 

     NSLog(@"arr..in table..%@",PostedItem); 
     cell.selectionStyle=UITableViewCellSelectionStyleNone; 

     if([[[PostedItem objectAtIndex:indexPath.row] valueForKey:@"productType"] isEqualToString :@"Video"]){ 
      cell.postedimage.image=[UIImage imageNamed:@"play_icon.png"]; 
     }else{ 

      if ([dicImages_msg valueForKey:[[PostedItem objectAtIndex:indexPath.row] valueForKey:@"productName"]]) { 

       cell.postedimage.image=[dicImages_msg valueForKey:[[PostedItem objectAtIndex:indexPath.row] valueForKey:@"productName"]]; 

      }else 
      { 
       if (!isDragging_msg && !isDecliring_msg) 
        { 
         [dicImages_msg setObject:[UIImage imageNamed:@"timthumb.jpg"] forKey:[[PostedItem objectAtIndex:indexPath.row] valueForKey:@"productName"]]; 
         [self performSelectorInBackground:@selector(downloadImage_3:) withObject:indexPath]; 
        } else 
         { 
          cell.postedimage.image=[UIImage imageNamed:@"timthumb.jpg"]; 
         } 
      } 

     } 
//*******************User image 
    if ([dic_usrImg valueForKey:[[PostedItem objectAtIndex:indexPath.row] valueForKey:@"thumbUrl"]]) { 

     cell.profileImage.image=[dic_usrImg valueForKey:[[PostedItem objectAtIndex:indexPath.row] valueForKey:@"thumbUrl"]]; 

    } 
    else 
    { 
     if (!isDragging_msg && !isDecliring_msg) 
     { 
      [dic_usrImg setObject:[UIImage imageNamed:@"timthumb.jpg"] forKey:[[PostedItem objectAtIndex:indexPath.row] valueForKey:@"thumbUrl"]]; 
      [self performSelectorInBackground:@selector(downloadImage_IMAGE4:) withObject:indexPath]; 
     } 
     else 
     { 
      cell.profileImage.image=[UIImage imageNamed:@"timthumb.jpg"]; 
     } 
    } 
//******************************** 
    [cell.btnImage setTag:100000+indexPath.row]; 
    [cell.btnImage addTarget:self action:@selector(Shopw_feedImg:) forControlEvents:UIControlEventTouchUpInside]; 
//*************** 
    cell.postedimage.tag=indexPath.row; 
    [cell.postedimage setUserInteractionEnabled:YES]; 
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onImageClick:)]; 
    [tap setNumberOfTouchesRequired:1]; 
    [tap setNumberOfTapsRequired:1]; 
    [tap setDelegate:self]; 
    [cell.postedimage addGestureRecognizer:tap]; 
    cell.membername.text=[[PostedItem objectAtIndex:indexPath.row] objectForKey:@"userName"]; 
    [cell.membername sizeToFit]; 
    //[[PostedItem objectAtIndex:indexPath.row] objectForKey:@"memberID"]; 
    cell.productName.text= [[PostedItem objectAtIndex:indexPath.row]objectForKey:@"photoTitle"]; 
    //@"hello this is a test doviumbmvbhdf asx"; 
    // with new sffhy dgftn tun dgh "; 
    // NSLog(@"Str Length...%d",[cell.productName.text length]); 
    if ([cell.productName.text length]>38) { 

     NSLog(@"greater then...%@",cell.productName.text); 
     cell.productName.numberOfLines=2; 
     CGRect frame=cell.postedimage.frame; 
     frame.origin.y=130; 
     cell.postedimage.frame=frame; 
     CGRect Prdctframe=cell.productName.frame; 
     frame.size.height=40.0f; 
     cell.productName.frame=Prdctframe; 
     //cell.postedimage.frame.origin.y=115.0f; 
    }//[[PostedItem objectAtIndex:indexPath.row]objectForKey:@"photoTitle"]; 
     //@"szfgfgbjmghufho stdogb ryt;o esftesi rdetg ry ry ry ";// 
    else 
    { 
     cell.productName.numberOfLines=1; 
     CGRect frame=cell.postedimage.frame; 
     frame.origin.y=110; 
     cell.postedimage.frame=frame; 
     CGRect Prdctframe=cell.productName.frame; 
     Prdctframe.size.height=20.0f; 
     cell.productName.frame=Prdctframe; 
      NSLog(@"less then..."); 
    } 

    //[cell.productName sizeToFit]; 
// cell.profileImage.image=[UIImage imageNamed:@"timthumb.jpg"]; 
    return cell; 
    } 

} 
संबंधित मुद्दे