我正在尝试从 url https://dl.dropboxusercontent.com/s/2iodh4vg0eortkl/facts.json获取数据
我在将 nsdata 转换为 nsdictionary 时得到了 nil。
我使用了以下代码。我也能够记录数据。但是一旦我将其转换为字典,它就会显示为零。我在这里错过了什么?
我也试过 nsurlsession 和 afnetworking。得到同样的错误。
NSError *error;
NSString *url_string = [NSString stringWithFormat: DATA_URL];
NSData *data = [NSData dataWithContentsOfURL: [NSURL URLWithString:url_string]];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"json: %@", json);
Run Code Online (Sandbox Code Playgroud) 我有一个文本字段,我输入一个值并保存并在tableView中检索它们.保存的最后一项显示在表格视图的底部.但我希望它显示在表格视图的顶部.
我尝试了以下代码但失败了.
- (void)viewDidLoad
{
CoreDataOneAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSEntityDescription *entityDesc =
[NSEntityDescription entityForName:@"Employee" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];
NSError *error;
objects = [[context executeFetchRequest:request error:&error]retain];
[request release];
[super viewDidLoad];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [objects count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
labelOne = [[UILabel alloc]initWithFrame:CGRectMake(5, 11, 110, 21)];
labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(230, 11, 70, 21)];
static NSString *cellIdentifier …Run Code Online (Sandbox Code Playgroud) 我想在我的数组中添加与对象一样多的标签.但是如何对齐它们?我想要一个低于另一个,并且id已经完成,它应该在下一列开始.但是我尝试将其覆盖另一个代码.
- (void)viewDidLoad
{
[super viewDidLoad];
array = [[ NSMutableArray alloc]initWithObjects:@"aaa",@"bbb",@"ccc",@"ddd",nil];
for( int i=0;i<[array count];i++)
{
NSString *theText = [array lastObject];
UILabel *label = [[UILabel alloc]init];
label.text = theText;
label.backgroundColor = [UIColor clearColor];
label.lineBreakMode = UILineBreakModeWordWrap;
label.frame = CGRectMake(0, label.frame.origin.y + label.frame.size.height, size.width + 20, size.height + 20);
[self.view addSubview:label];
}
}
Run Code Online (Sandbox Code Playgroud) ios ×3
objective-c ×2
afnetworking ×1
cocoa-touch ×1
core-data ×1
iphone ×1
json ×1
nsurlsession ×1
uilabel ×1
uitableview ×1
xcode ×1