2011-09-15 96 views
0

基本上,從導航控制器的根,表視圖,我建立一個URL字符串,其中包含我想要在新的tableView上顯示的信息。在新的表格視圖中,我使用URL作爲NSURL請求。我的代碼給我沒有錯誤,但崩潰,在NSLog後:造成細胞。幫我殺死自己之前。對不起,應該都在一起,但複製粘貼代碼顯然不能很好地工作。UITableView崩潰沒有erros

#import "CatDisplayViewController.h" 
#import "CatViewController.h" 


implementation CatDisplayViewController 

@synthesize downvotebutton; 
@synthesize upvotebutton; 
//@synthesize tripsHold; 
@synthesize URLtoUse; 






NSArray *trips; 


- (void)viewDidLoad { 
[super viewDidLoad]; 



NSURL *url = [NSURL URLWithString:URLtoUse]; 

NSLog(@"%@", url); 

responseData = [[NSMutableData data] retain]; 

NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
[[NSURLConnection alloc] initWithRequest:request delegate:self]; 

}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { 
NSLog(@" recieved response "); 
[responseData setLength:0]; 

}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 
NSLog(@" Did recieve data "); 
[responseData appendData:data]; 

}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { 
NSLog(@" connection failed "); 
NSLog(@"%@", error); 

}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection { 
[connection release]; 
NSLog(@" our connect finished loading"); 
NSString *responseString = [[NSString alloc] initWithData:responseData  encoding:NSUTF8StringEncoding]; 
[responseData release]; 

NSLog(@"%@", responseString); 

NSLog(@" released data "); 
NSDictionary *results = [responseString JSONValue]; 
NSLog(@" built JSON dictionary "); 
NSArray *allTrips = [results objectForKey:@"results"]; 
NSLog(@" built array from dictionary "); 

trips = allTrips; 
NSLog(@" done with connectFinish method "); 

[self.tableView reloadData]; 

}

#pragma mark - 
#pragma mark Table view data source 



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
// Return the number of sections. 

NSLog(@" in sections number "); 

return 1; 

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
// Return the number of rows in the section. 
NSLog(@"%@", trips); 
return [trips count]; 

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@" in height for row "); 
return 80; 
} 


// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
NSLog(@" Trying to build table "); 
static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
} 

// Configure the cell... 
NSLog(@"made cells"); 

NSDictionary *trip = [trips objectAtIndex:[indexPath row]]; 

NSLog(@" made dictionary from array "); 

cell.textLabel.text = [trip objectForKey:@"txt"]; 
cell.textLabel.adjustsFontSizeToFitWidth = YES; 
cell.textLabel.font = [UIFont systemFontOfSize:12]; 
cell.textLabel.minimumFontSize = 10; 
cell.textLabel.numberOfLines = 4; 
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap; 

cell.detailTextLabel.text = [trip objectForKey:@"name"]; 

UIButton *upvote =[UIButton buttonWithType:UIButtonTypeRoundedRect]; 

UIImage *upVoteBack = [UIImage imageNamed:@"arrowup.png"]; 
[upvote setBackgroundImage:upVoteBack forState:UIControlStateNormal]; 
[upvote setTitle:@"+" forState:UIControlStateNormal]; 
upvote.frame = CGRectMake(250.0f, 40.0f, 25.0f, 25.0f); 
[upvote addTarget:self action:@selector(upvoteaction:)forControlEvents:UIControlEventTouchUpInside]; 
[cell addSubview:upvote]; 

UIButton *downvote =[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
UIImage *downVoteBack = [UIImage imageNamed:@"arrowdown.png"]; 
[upvote setBackgroundImage:downVoteBack forState:UIControlStateNormal]; 
[downvote setTitle:@"-" forState:UIControlStateNormal]; 
downvote.frame = CGRectMake(250.0f, 40.0f, 25.0f, 25.0f); 
[downvote addTarget:self action:@selector(downvoteaction:)forControlEvents:UIControlEventTouchUpInside]; 
[cell addSubview:downvote]; 



//NSURL *url = [NSURL URLWithString:[aTweet objectForKey:@"profile_image_url"]]; 
//NSData *data = [NSData dataWithContentsOfURL:url]; 
//cell.imageView.image = [UIImage imageWithData:data]; 
cell.selectionStyle = UITableViewCellSelectionStyleNone; 
return cell; 

}

+0

'_copy粘貼代碼顯然不能很好地工作' - 所以編輯它,直到它看起來正確然後 - 有一個預覽窗口的原因;) – deanWombourne

回答

0
trips = [allTrips retain]; 

您的旅行陣列被自動釋放 - 嘗試保留它nd看看你是否仍然有錯誤。

+0

omg nevermind不回答我有錯誤的按鈕類型,應該是自定義的。非常感謝你是一位上帝該死的上師,我在字面上發佈了這樣的信息,就像在你迴應之前5分鐘一樣......當我們發佈它時,幾乎感覺像一張紙條,感謝死者的女性(他可能應該寫這篇全文)=] – gma

+0

如果你喜歡我的回答,可以點擊投票按鈕下面的灰色勾號給我一些聲望。 。 。 。 ;) 很高興我能幫上忙。 – deanWombourne

+0

好吧,我會嘗試,但是,我沒有一個帳戶,你的意思是複選標記?因爲我點擊了它,但還有一件事,我只是做了一個UI選擇器視圖,一切都很順利,但是你有什麼想法,當滾動停止選擇時如何禁用自動選擇?我的「老闆」告訴我「弄明白」他想讓它點擊選擇,我不想在這個選擇器工作得很好時去嘗試製作一個愚蠢的小桌面。 – gma