我正在编写代码,允许我的iphone-app有一个"配置页面".
一个分组,滚动,UITableView ...与包含所需textFields,开关,滑块等的单元格.
这是一个非常多的代码.有没有更简单的方法?
有没有办法我可以创建一个简单的文本文件,包含我所需的所有设计选择,并让我(可重用)代码为我构建TableView?
或者......我可以在Interface Builder而不是代码中更快/更轻松地完成整个事情吗?
此代码与networkActivityIndicatorVisible一起使用是否正确?
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
UIApplication* app2 = [UIApplication sharedApplication];
app2.networkActivityIndicatorVisible = YES;
[self loadSources]; // Loads data in table view
app2.networkActivityIndicatorVisible = NO;
}
Run Code Online (Sandbox Code Playgroud)
张志贤
如何根据字典键获取唯一值,字典键是目标C中数组的元素?
例如:
我有一个项目数组
aryItem
aryItem[0] = Dictionary{
ItemCategory
ItemName
ItemPrice
}
aryItem[1] = Dictionary{
ItemCategory
ItemName
ItemPrice
}
...........
...........
aryItem[n] = Dictionary{
ItemCategory
ItemName
ItemPrice
}
Run Code Online (Sandbox Code Playgroud)
现在我想获得唯一的ItemCategory,而不是重复.如果我可以写[[aryItem objectatIndex:i] valueForKey:ItemCategory]我得到所有类别,同样的类别也包括在内.我只需要独特的类别.我有一个选项搜索整个数组然后获得唯一的Itemcategory对象,但我正在寻找任何简短的方法来完成相同的事情.
谢谢.
我有一个navigationBar,它的标题上有UIImage,如下所示:
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"top_logo.png"]];
Run Code Online (Sandbox Code Playgroud)
当我选择一行时,不会出现"后退"按钮.为什么?
我在其他的viewControllers上有完全相同的代码,它出现了.我不明白为什么......
谢谢,
RL
我正在尝试解析保存在doc dir下面的文本文件show是它的代码
NSArray *filePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *docDirPath=[filePaths objectAtIndex:0];
NSString *filePath=[docDirPath stringByAppendingPathComponent:@"SKU.txt"];
NSError *error;
NSString *fileContents=[NSString stringWithContentsOfFile:filePath];
NSLog(@"fileContents---%@",fileContents);
if(!fileContents)
NSLog(@"error in reading file----%@",error);
NSArray *values=[fileContents componentsSeparatedByString:@"\n"];
NSLog(@"values-----%@",values);
NSMutableArray *parsedValues=[[NSMutableArray alloc]init];
for(int i=0;i<[values count];i++){
NSString *lineStr=[values objectAtIndex:i];
NSLog(@"linestr---%@",lineStr);
NSMutableDictionary *valuesDic=[[NSMutableDictionary alloc]init];
NSArray *seperatedValues=[[NSArray alloc]init];
seperatedValues=[lineStr componentsSeparatedByString:@","];
NSLog(@"seperatedvalues---%@",seperatedValues);
[valuesDic setObject:seperatedValues forKey:[seperatedValues objectAtIndex:0]];
NSLog(@"valuesDic---%@",valuesDic);
[parsedValues addObject:valuesDic];
[seperatedValues release];
[valuesDic release];
}
NSLog(@"parsedValues----%@",parsedValues);
NSMutableDictionary *result;
result=[parsedValues objectAtIndex:1];
NSLog(@"res----%@",[result objectForKey:@"WALM-FT"]);
Run Code Online (Sandbox Code Playgroud)
我面临的问题是,当我尝试打印lineStr即文本文件的数据时,它打印为单个字符串,因此我无法逐行获取内容,请帮我解决此问题.
我正在开发一个小应用程序,其中我有多个NSURLConnection.I已创建NSURL连接但我不知道如何处理它.我的代码如下所示.
-(void) loadTrafficAndEvent {
int a=10;
//Get the map view bounds for fetch the travel time markers from web service
MKCoordinateRegion region = mapView.region;
float print = region.center.latitude;
// NSLog(@"region.center=%g",print);
CGPoint firstcorner = CGPointMake(self.mapView.bounds.origin.x , mapView.bounds.origin.y);
CGPoint secondcorner = CGPointMake((self.mapView.bounds.origin.x+mapView.bounds.size.width) , mapView.bounds.origin.y);
CGPoint thirdcorner = CGPointMake(self.mapView.bounds.origin.x , (mapView.bounds.origin.y+ mapView.bounds.size.height));
CGPoint fourthcorner = CGPointMake((self.mapView.bounds.origin.x+mapView.bounds.size.width), (mapView.bounds.origin.y + mapView.bounds.size.height));;
//Then transform those point into lat,lng values
CLLocationCoordinate2D mapfirstcorner,mapsecondcorner,mapthirdcorner,mapfourthcorner,requestsender;
mapfirstcorner = [mapView convertPoint:firstcorner toCoordinateFromView:mapView];
mapsecondcorner = [mapView convertPoint:secondcorner toCoordinateFromView:mapView];
mapthirdcorner = [mapView convertPoint:thirdcorner toCoordinateFromView:mapView]; …Run Code Online (Sandbox Code Playgroud) NSArray *arr=[[NSArray alloc]init]; //Am getting all immutable objects allocation that retain count:2
NSLog(@"dic1:%d",[arr retainCount]);
[arr retain];
[arr retain];
[arr retain];
[arr release];
NSLog(@"dic2:%d",[arr retainCount]);
NSMutableDictionary *dic=[[NSMutableDictionary alloc]init];//Am getting all mutable objects allocation that retain count:1
NSLog(@"dic3:%d",[dic retainCount]);
[dic retain];
[dic retain];
[dic retain];
[dic release];
NSLog(@"dic4:%d",[dic retainCount]);
Run Code Online (Sandbox Code Playgroud)
输出:dic1:2 dic2:4 dic3:1 dic4:3
可变对象之间的差异是什么,保留计数和不可变对象保留计数?请给我解决方案...
我不想将方法作为参数传递给另一个方法,因此它知道在结束运行时调用的方法.可能吗?
[self bringJSON:(NSString *)_passedValua:(NSObject *)anotherMethod];
Run Code Online (Sandbox Code Playgroud) 当我完成它们时,这些日期指针中的任何一个或两个都需要[发布].我怎么知道这个?我不确定,因为我没有明确地做init.
NSDate *date = [NSDate date];
NSDate *date = [dateWithTimeIntervalSince1970:100000000];
Run Code Online (Sandbox Code Playgroud) 我用ASIHTTPReqeust下载文件.一切都下载得很好,但它无法将文件从临时目录移动到文档.当我实施
-(void) request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data
Run Code Online (Sandbox Code Playgroud)
请求失败并显示错误.但文件已下载.
如果我删除此实现,一切都很好,文件正在转移到文档.这是错误文本:
Error Domain=ASIHTTPRequestErrorDomain Code=8 "Failed to move file from '/var/folders/Qu/Qu0o0VcpEY4npJr2C1yPzE+++TI/-Tmp-/Skrillex feat. Nero - Wobbleland.mp3' to '/Users/Timur/Library/Application Support/iPhone Simulator/4.3/Applications/34389282-4013-4354-95D9-DF2847B4EE55/Documents/Audio/Skrillex feat. Nero - Wobbleland.mp3'" UserInfo=0x5949520 {NSUnderlyingError=0x59992a0 "The operation couldn’t be completed. (Cocoa error 4.)", NSLocalizedDescription=Failed to move file from '/var/folders/Qu/Qu0o0VcpEY4npJr2C1yPzE+++TI/-Tmp-/Skrillex feat. Nero - Wobbleland.mp3' to '/Users/Timur/Library/Application Support/iPhone Simulator/4.3/Applications/34389282-4013-4354-95D9-DF2847B4EE55/Documents/Audio/Skrillex feat. Nero - Wobbleland.mp3'}
Run Code Online (Sandbox Code Playgroud)
谁有类似的问题?
iphone ×6
objective-c ×6
xcode ×3
ios ×2
filesystems ×1
ios4 ×1
methods ×1
nsdate ×1
parameters ×1
release ×1
retaincount ×1
text-parsing ×1
uitableview ×1