2014-02-06 32 views
-2

當我嘗試使用標題構建自定義表視圖時出現奇怪的錯誤。這裏是我的代碼:奇怪的錯誤自定義表視圖

@interface DEMOSecondViewController() 

@end 

@implementation DEMOSecondViewController 
@synthesize tableView = _tableView, activityIndicatorView = _activityIndicatorView; 
@synthesize fontForCellText; 
@synthesize btnFaceBook, btnTwitter, btnTwitter2; 
@synthesize strURLToLoad; 
@synthesize movies; 

- (void)refresh:(UIRefreshControl *)refreshControl { 
    [refreshControl endRefreshing]; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; 
    [refreshControl setTintColor:[UIColor greenColor]]; 
    [refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged]; 
    [self.tableView addSubview:refreshControl]; 

    strURLToLoad = [[NSMutableString alloc] init]; 

    [btnFaceBook setTitle:@"link-1" forState:UIControlStateDisabled]; 
    [btnTwitter setTitle:@"link-2" forState:UIControlStateDisabled]; 
    [btnTwitter2 setTitle:@"link-3" forState:UIControlStateDisabled]; 

    [btnFaceBook setBackgroundImage:[UIImage imageNamed:@"tab_selected.png"] forState:UIControlStateNormal]; 
    [btnFaceBook setBackgroundImage:[UIImage imageNamed:@"tab_unselected.png"] forState:UIControlStateSelected]; 

    [btnTwitter setBackgroundImage:[UIImage imageNamed:@"tab_selected.png"] forState:UIControlStateNormal]; 
    [btnTwitter setBackgroundImage:[UIImage imageNamed:@"tab_unselected.png"] forState:UIControlStateSelected]; 

    [btnTwitter2 setBackgroundImage:[UIImage imageNamed:@"tab_selected.png"] forState:UIControlStateNormal]; 
    [btnTwitter2 setBackgroundImage:[UIImage imageNamed:@"tab_unselected.png"] forState:UIControlStateSelected]; 



    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PostsObject" owner:self options:nil]; 
    PostsObject *cell = [nib objectAtIndex:0]; 
    fontForCellText = cell.title.font; 
    cellTextWidth = cell.title.frame.size.width; 
    cellHeightExceptText = cell.frame.size.height - cell.title.frame.size.height; 

    [self.navigationController setNavigationBarHidden:YES]; 

    self.tableView.separatorColor = [UIColor clearColor]; 

    // Setting Up Activity Indicator View 
    self.activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 

    self.activityIndicatorView.color = [UIColor greenColor]; 


    self.activityIndicatorView.hidesWhenStopped = YES; 
    self.activityIndicatorView.center = self.view.center; 
    [self.view addSubview:self.activityIndicatorView]; 
    [self.activityIndicatorView startAnimating]; 
    self.tableView.separatorColor = [UIColor clearColor]; 

    // Initializing Data Source 
    movies = [[NSMutableArray alloc] init]; 

    [self btnFromTabBarClicked:btnFaceBook]; 
} 

-(UIStatusBarStyle)preferredStatusBarStyle{ 
    return UIStatusBarStyleLightContent; 
} 

- (void)loadJSONFromCurrentURL 
{ 
    [self.activityIndicatorView startAnimating]; 

    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:strURLToLoad]]; 

    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { 
     [movies setArray:JSON]; 
     [self.activityIndicatorView stopAnimating]; 
     [self.tableView reloadData]; 

    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { 
     NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo); 
    }]; 

    [operation start]; 
} 

- (IBAction)btnFromTabBarClicked:(UIButton *)sender 
{ 
    //Unselect all 3 buttons 
    btnFaceBook.selected = btnTwitter.selected = btnTwitter2.selected = NO; 

    //Select the button that was clicked 
    sender.selected = YES; 

    //Set the string of an NSMutableString property called strURLToLoad with the URL 
    //The URL is pre stored in the text of the UIButton in the Disabled text. 
    [strURLToLoad setString:[sender titleForState:UIControlStateDisabled]]; 

    //Load the URL 
    [self loadJSONFromCurrentURL]; 
} 

// Table View Data Source Methods 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    if (section==0) { 
     return 0; 
    } else { 
     return movies.count; 
    } 
} 

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (indexPath.section == 0) { 
     static NSString *Identifier1 = @"TableHeaderView"; 

     // cell type 1 
     TableHeaderView *cell = [tableView dequeueReusableCellWithIdentifier:Identifier1]; 

     if (cell == nil) { 
      NSArray *nib= [[NSBundle mainBundle] loadNibNamed:@"TableHeaderView" owner:self options:nil]; 
      cell = (TableHeaderView *)[nib objectAtIndex:0]; 
     } 

     return cell; 

    } else { 

     static NSString *Identifier2 = @"PostsObject"; 
     // cell type 2 
     PostsObject *cell = [tableView dequeueReusableCellWithIdentifier:Identifier2]; 
     if (cell == nil) { 
      NSArray *nib= [[NSBundle mainBundle] loadNibNamed:@"PostsObject" owner:self options:nil]; 
      cell = (PostsObject *)[nib objectAtIndex:0]; 
     } 

     NSDictionary *movie = [self.movies objectAtIndex:indexPath.row]; 
     NSString *strText = [movie objectForKey:[self getTextKey]]; 

     CGRect rect = cell.title.frame; 
     rect.size.height = [self getHeightForText:strText]; 
     cell.title.frame = rect; 
     cell.title.text = strText; 
     cell.arrow.center = CGPointMake(cell.arrow.frame.origin.x, rect.origin.y + rect.size.height/2); 
     cell.published.text = [movie objectForKey:[self getPostedTime]]; 
     cell.twitterName.text = [movie objectForKey:[self getTwitterName]]; 
     return cell; 
    } 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    NSDictionary *selectedMovie = self.movies[indexPath.row]; 

    PostsNextView *nextVC = [[PostsNextView alloc] initWithDictionary:movies]; 

    [self.navigationController pushViewController:nextVC animated:YES]; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSDictionary *movie = [self.movies objectAtIndex:indexPath.row]; 
    NSString *strText = [movie objectForKey:[self getTextKey]]; 

    CGFloat cellHeight = cellHeightExceptText + [self getHeightForText:strText]; 

    return cellHeight; 
} 

- (NSString *)getTextKey 
{ 
    return [email protected]"tweet":@"message"; 
} 

- (NSString *)getPostedTime 
{ 
    return [email protected]"posted":@"published"; 
} 

- (NSString *)getTwitterName 
{ 
    return [email protected]"user":@"celebname"; 
} 

- (CGFloat)getHeightForText:(NSString *)strText 
{ 
    CGSize constraintSize = CGSizeMake(cellTextWidth, MAXFLOAT); 
    CGSize labelSize = [strText sizeWithFont:fontForCellText constrainedToSize:constraintSize lineBreakMode:NSLineBreakByWordWrapping]; 
    NSLog(@"labelSize.height = %f",labelSize.height); 
    return labelSize.height; 
} 


@end 

我得到的return 2行錯誤:

error

有人能解釋一下嗎?

+4

似乎是一個斷點並不是一個錯誤,我... – AncAinu

+2

似乎有超過30個斷點設置... –

回答

3

這不是一個錯誤,它是一個斷點。刪除它,它會很好。

1

將你的斷點(即藍色箭頭)拖到某個地方去除。

enter image description here