我正在加载一个JSON,但我想检查"URL": "",json中是否为空,有时ID是空的,我该怎么检查?
if(URL == HOW TO CHECK IF EMPTY?)
{
}
else
{
}
Run Code Online (Sandbox Code Playgroud)
错误:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
Run Code Online (Sandbox Code Playgroud) 我正在尝试更新我的UITableview,但是当我调用[tableView reloadData];表时不会更新,在我更改后滚动tableview上面的单元格名称.但它并没有添加新的行或类似的东西.
-(void)update {
[tableView reloadData];
NSLog(@" %i", [tableData count]);
}
Run Code Online (Sandbox Code Playgroud)
当我添加一行它返回2但是表没有更新时,nslog正在退回1.
- (void) refresh:(id)sender {
NSString *jsonString = [NSString
stringWithContentsOfURL:[NSURL URLWithString:xmlDataUrl]
encoding:NSUTF8StringEncoding
error:nil];
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *results = [parser objectWithString:jsonString error:nil];
parser = nil;
[self setTableData:[results objectForKey:@"items"]];
[self performSelector:@selector(update) withObject:nil afterDelay:.2];
}
Run Code Online (Sandbox Code Playgroud)
.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// Change UITableViewCellStyle
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle …Run Code Online (Sandbox Code Playgroud) 我已经以UITabBar编程方式定义了一个但是如何UITabBar在项目处于活动状态时设置自定义图标?
这是我用于声明UITabBar按钮的代码,但是如何在活动时设置自定义图像?
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Free", @"Free");
self.tabBarItem.image = [UIImage imageNamed:@"Free.png"];
}
return self;
}
Run Code Online (Sandbox Code Playgroud) 通常我正在解析像(例子)的JSON提要;
{
"AppStore": [
{
"Application": "Game",
"KeyID": "zero"
}
]
}
Run Code Online (Sandbox Code Playgroud)
在我的JSON中,我正在做
NSArray* Parse = [json objectForKey:@"AppStore"];
Run Code Online (Sandbox Code Playgroud)
但我现在想解析它有另一个结构的AppStore的JSON
http://itunes.apple.com/lookup?id=387633954
{
"resultCount": 1,
"results": [
{
"kind": "software",
"features": [
"gameCenter",
"iosUniversal"
],
"supportedDevices": [
"all"
],
"isGameCenterEnabled": true,
"artistViewUrl": "http://itunes.apple.com/us/artist/mcsebi/id387633957?uo=4",
"artworkUrl60": "http://a5.mzstatic.com/us/r1000/072/Purple/v4/98/a6/56/98a656e8-666a-89ab-c8f0-878b61b9f8f2/Icon.png",
"screenshotUrls": [
"http://a3.mzstatic.com/us/r1000/076/Purple/v4/fe/36/80/fe3680ae-5439-a2f1-6675-d3246b64f333/mza_11015238406403423.png",
"http://a4.mzstatic.com/us/r1000/099/Purple/v4/73/98/1c/73981cbf-fb79-dc38-9dac-61ab46c2ac60/mzl.gzibbhfx.png",
"http://a3.mzstatic.com/us/r1000/103/Purple/v4/72/b6/87/72b68713-7e5a-f675-83c3-85c2f0e96df1/mzl.gykakuht.png",
"http://a1.mzstatic.com/us/r1000/113/Purple/v4/fa/d6/c4/fad6c453-9da5-2506-2b06-42ed5ff6bd63/mzl.hqbrlhog.png",
"http://a2.mzstatic.com/us/r1000/120/Purple/v4/9e/7a/13/9e7a1388-5089-11e7-0c03-3d1868abbb82/mzl.jogfcyqv.png"
],
"ipadScreenshotUrls": [
"http://a1.mzstatic.com/us/r1000/096/Purple/v4/1f/5a/92/1f5a9249-03b8-90dc-8226-18b1785d5f7d/mzl.ilqgfose.1024x1024-65.jpg",
"http://a5.mzstatic.com/us/r1000/070/Purple/v4/79/74/6b/79746ba8-7ea0-6e81-93d0-9e2493412e21/mzl.saleskru.1024x1024-65.jpg",
"http://a1.mzstatic.com/us/r1000/068/Purple/v4/12/38/91/1238914f-7387-9c9e-06e4-11a55871b04a/mzl.qmiockwv.1024x1024-65.jpg",
"http://a4.mzstatic.com/us/r1000/091/Purple/v4/3b/cf/62/3bcf62e6-4d84-4fc0-e721-c328361f5c95/mzl.somobtxy.1024x1024-65.jpg",
"http://a1.mzstatic.com/us/r1000/074/Purple/v4/e9/d3/e7/e9d3e7b7-b52c-e204-e4b6-1ab5de79e85a/mzl.nedztyfk.1024x1024-65.jpg"
],
"artworkUrl512": "http://a3.mzstatic.com/us/r1000/115/Purple/v4/0d/9c/ec/0d9cec04-91b3-5fe2-fa40-100660250f4a/mzl.kavmnegm.png",
"artistId": 387633957,
"artistName": "McSebi",
"price": 0.99,
"version": "1.2",
"description": "Connect M is a simple, but very addictive puzzle game. …Run Code Online (Sandbox Code Playgroud) 我正在从Apple JSON(应用程序的评级)解析一些东西,我尝试了类似的东西:
if ([StoreParse objectForKey:@"averageUserRating"] == @"4.5") {
NSLog(@"xx");
} else {
NSLog(@"xxx");
}
Run Code Online (Sandbox Code Playgroud)
该应用程序的评级为4.5,如果我这样做
NSlog (@"%@", [StoreParse objectForKey:@"averageUserRating"]);
Run Code Online (Sandbox Code Playgroud)
输出为:4.5
但是当我运行脚本时,第一个代码输出中的NSlog是"xxx",有人可以帮助我吗?
cocoa-touch ×3
objective-c ×3
cocoa ×2
ios ×2
ios5 ×2
xcode ×2
iphone ×1
uitableview ×1
url ×1