2011-09-15 4 views
0

基本的には、ナビゲーションコントローラのルートからテーブルビューを作成し、新しいtableViewに表示したい情報を含むURL文字列を作成します。新しいテーブルビューでは、NSURLリクエストのURLを使用します。私のコードではエラーは出ませんが、NSLogの直後にクラッシュしました。私は自分を殺す前に助けてください。申し訳ありませんがすべて一緒になる必要がありますコピー貼り付けコードは明らかにうまく動作しません。エラーなしでUITableViewがクラッシュする

#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]; 

ご旅行の配列が自動解放されている - それは保持してみてくださいそれでもエラーが出るかどうかを確認してください。

+0

omg notmould notは間違ったボタンタイプを持っていました。あなたが応答した5分前のように、私は文字通りそれを投稿しました....私たちがそれをリリースしたときにメモを作成するような気がしていました.DAN WOMBOURNEに感謝します(彼は本当にこれをすべて手に入れてください)=] – gma

+0

私の答えが好きなら、投票ボタンのすぐ下にある左の灰色の刻みをクリックして、私にいくつかの評判を与えてください。 。 。 。 ;) お役に立てて嬉しいです。 – deanWombourne

+0

しかし、私はアカウントを持っていないが、チェックマークを意味するのだろうか?私はそれをクリックしたが、もう1つ、UIピッカーのビューを作成してすべてスムーズに行ったが、スクロールが選択範囲で停止したときに自動ピッキングを無効にする方法はありますか?私の "上司"は、 "選択してください"をクリックしたいと思うcuaseを私に言った、そして私はこのピッカーがうまく動作するときに愚かな小さなtableviewを作ろうとしたくない。 – gma

関連する問題