問題:我已經從Windows Azure中讀取了值。通過NSLogs,我能夠看到我的應用程序確實從Azure服務器的表中讀入。但是,顯示值已成爲一個問題。在NSMutable陣列中輸出讀取
情況:到目前爲止,我在ViewController.m文件中有一個NSMutableArray對象。我已經訪問了數組,並能夠從表中讀取結果(在windows azure中)賦值給mutableArray。我的問題是,我試圖通過tableview顯示它,但沒有顯示,當我向下移動表視圖時,應用程序崩潰。
相信的主要問題是這一行:
cell.textLabel.text = [俱樂部objectAtIndex:indexPath.row];
請與我裸露,我是新來的Xcode和Objective-C
這裏是ViewController.m代碼:
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController{
NSDictionary *courseDetails;
NSArray *justCourseNames;
NSDictionary *webcourseDetails;
NSArray *webjustCourseNames;
NSDictionary *clubNames;
NSArray *location;
NSMutableArray *clubs;
NSInteger amount;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
if (section == 0)
{
return @"Milton Keynes";
}
else{
return @"Stafford";
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section == 0)
{
return clubs.count;
}
else{
return webcourseDetails.count;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
UIImage *image = [UIImage imageNamed:@"ClubCellImage"];
[cell.imageView setImage:image];
//removing the line of code below seems to fix the crash. this is the line of code to display the details
cell.textLabel.text = [clubs objectAtIndex:indexPath.row];
/*if (indexPath.section == 0)
{
//cell.textLabel.text = justCourseNames[indexPath.row];
//cell.detailTextLabel.text = courseDetails[justCourseNames[indexPath.row]];
}
else
{
cell.textLabel.text = clubs[indexPath.row];
//cell.textLabel.text = webjustCourseNames[indexPath.row];
//cell.detailTextLabel.text = webcourseDetails[webjustCourseNames[indexPath.row]];
}*/
return cell;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.client = [MSClient clientWithApplicationURLString:@"https://clublocatortimogunmakin.azure-mobile.net/"
applicationKey:@"ecxnaXEfNpeOvwYYgcViJJoumZlZng45"];
// Do any additional setup after loading the view.
NSURL *url = [[NSBundle mainBundle] URLForResource:@"courses" withExtension:@"plist"];
MSTable *itemTable = [_client tableWithName:@"Item"];
courseDetails = [NSDictionary dictionaryWithContentsOfURL:url];
justCourseNames = courseDetails.allKeys;
NSURL *weburl = [[NSBundle mainBundle] URLForResource:@"courses_web" withExtension:@"plist"];
webcourseDetails = [NSDictionary dictionaryWithContentsOfURL:weburl];
webjustCourseNames = courseDetails.allKeys;
[itemTable readWithCompletion:^(NSArray *results, NSInteger totalCount, NSError *error) {
clubs = [results mutableCopy];
amount = totalCount;
if (error) {
NSLog(@"Error: %@", error);
} else {
//NSLog(@"Item read, id: %@", [results objectAtIndex:1]);
for (int i = 0; i < results.count; i++)
{
NSLog(@"Item read, id: %@", [results objectAtIndex:i]);
}
}
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
你可以添加崩潰日誌嗎? – lucianomarisi
這是你在找什麼?16 CoreFoundation 0x01cb236e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30 –