我在点击"self.myData = ..."这一行时遇到异常
GDB程序收到信号:EXC_BAD_ACCESS
这是我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.myData = [NSArray arrayWithObjects:
[NSArray arrayWithObjects:
@"Boroughs",
[NSArray arrayWithObjects:
@"Kings",
@"Bronx",
@"Manhattan",
@"Queens",
@"Staten Island",
nil],
nil],
[NSArray arrayWithObjects:
@"Surrounding Counties",
[NSArray arrayWithObjects:
@"Westchester",
@"Nassau",
@"Suffolk",
"@Fairfield",
nil],
nil],
nil];
}
Run Code Online (Sandbox Code Playgroud) 我一直在努力解决这个问题(我昨晚一直在醒来,把头撞在墙上)但希望有人在这里可以帮助我.
我已经使用本教程连接到我的JSON数据源(http://www.mobileorchard.com/tutorial-json-over-http-on-the-iphone/)并且它工作正常但我现在想要获取值(通过对象键我认为).
我的json数据如下:[{"Id":"1","Name":"Richard","NameOfFile":"1.jpg"},{"Id":"395","Name":"亚历克斯", "NameOfFile": "390.jpg"}]
我用来连接它的代码如下.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
SBJSON *json = [[SBJSON new] autorelease];
NSArray *myArray = [json objectWithString:responseString error:nil];
[responseString release];
for (int i = 0; i < [myArray count]; i++)
{
for(int colIndex = 0; colIndex < 5; colIndex++)
{
UIImage * myimage = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: @"http://www.goweruk.com/Images/Uploaded/220/873.jpg"]]];
UIImageView *myimageview = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f,50.0f, 50.0f)];
[myimageview setImage:myimage];
CGRect frameRect = myimageview.frame; …Run Code Online (Sandbox Code Playgroud) 可能重复:
NSArray中的最大对象数量
我只是想知道我可以在NSArray中放入多少个对象,因为我需要找到像数组一样的函数,但我需要保存大量数据(在900到1200个字符串之间).我正在考虑使用NSDictionary来保存数据,但它似乎不符合要求.你认为NSArray会持有那么多对象,还是应该使用NSDictionary?
我有一个Person对象数组(具有许多属性).我想用Person的"fullname"属性创建另一个数组.有没有一种简单的方法可以做到这一点,除了显而易见的方法:迭代原始数组,并将fullname一个接一个地复制到另一个数组中?我们可以执行此initWithArray:并告诉它在复制时使用对象的fullname属性吗?
当我向下滚动UITableView时,我的iPhone应用程序崩溃了.我将NSZombieEnabled设置为YES,并发现我用来填充表的NSArray正在以某种方式被释放.
#import "RootViewController.h"
@implementation RootViewController
@synthesize flashsets;
- (void)viewDidLoad
{
//Unrelated code removed from this post
NSString *listofsetsstring = [[NSString alloc]
initWithContentsOfFile:pathtosetsdata
encoding:NSUnicodeStringEncoding
error:&error];
flashsets = [listofsetsstring componentsSeparatedByString:@"\n"];
[super viewDidLoad];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [flashsets count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure …Run Code Online (Sandbox Code Playgroud) 我使用下面的代码检查ary_navigationControllerViews数组包含myclass对象或不工作正常,但我需要for for循环.我知道我们有像containsObject这样的方法但在这种情况下如何使用.有没有办法检查这个条件没有使用for循环.
NSArray *ary_navigationControllerViews = [[NSArray alloc] initWithArray:[self.navigationController viewControllers]];
for(id obj_viewController in ary_navigationControllerViews) {
if([obj_viewController isKindOfClass:[myClass class]]) {
//some my code
return;
}
}
Run Code Online (Sandbox Code Playgroud) 在Java中,我通常初始化特定大小的数组,然后在我的代码继续时添加和替换对象.在Objective C中,我不能用NSArray做到这一点.我从Java移植的代码通常必须使用NSMutableArray,我认为它的执行效率低于NSArray.(我最好猜测NSMutableArray如何存储它的成员是使用链表,但我可能是错的)
Objective C中是否有任何类型的数组具有固定的大小并允许在数组中进行更改?为什么不能用NSArray替换某个对象的对象?我可以用C数组做到这一点,为什么不用Objective C?
我需要在Objective-C中使用带有NSArray的IN子句来执行Select语句.像这样的东西
NSArray *countries = [NSArray arrayWithObjects:@"USA", @"Argentina", @"England", nil];
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
const char *sqlStatement =
[[NSString stringWithFormat:@"select currencies from money where country IN countries] UTF8String];
....
Run Code Online (Sandbox Code Playgroud)
其中IN国家是带有字符串值的NSArray.这是真的吗?
背景资料:
我编写了一个包含2个图库的iOS应用程序:本地图库和服务器库.当用户更新服务器库并将其合并到本地服务器库时,应用程序应该只下载新图像.
为了最大限度地减少内存消耗,我保存了图像并使用ImageEntity具有以下属性的类的实例填充数组:fileName,filePath和votingStatus.
我尝试使用以下逻辑来检查图像是否已存在:
for (ImageEntity *imageEntity in self.serverImagesArray) {
if (![self.localImagesArray containsObject:imageEntity]){
[self.localImagesArray addObject:imageEntity];
}
}
Run Code Online (Sandbox Code Playgroud)
但是因为每个实体都是一个单独的对象,所以它总是被添加.但是每个实体都有一个唯一的fileName.
问题:
我可以以某种方式扩展[NSArray containsObject:]函数以检查数组中的一个对象是否具有等于"someValue"的属性?(当我将Cocoa-Bindings与ArrayController结合使用时,我可以分配数组元素的属性 - 我想访问与此类似的属性).
我知道我可以使用比较本地数组的每个实体与服务器阵列上的每个元素.我不得不进行O(n ^ 2)比较,画廊可能包含数百张图像.
奖金问题:我是否已经在没有意识到的情况下这样做了?有没有人有关于Apple实现此功能的详细信息?是否有一些奇特的实现,或者他们只是在比较每个元素的数组上进行迭代?
我有一个数组包含mutableCopy中Store类型的对象.我发布数组,在释放数组之前释放所有对象吗?
NSMutableArray *stores=[[NSMutableArray alloc]init];
[stores addObject:[store1 mutableCopy]];
[stores addObject:[store2 mutableCopy]];
[stores addObject:[store3 mutableCopy]];
...
[stores release];
Run Code Online (Sandbox Code Playgroud) nsarray ×10
objective-c ×7
iphone ×4
cocoa ×2
arrays ×1
comparison ×1
ios ×1
java ×1
json ×1
memory-leaks ×1
nsdictionary ×1
performance ×1
sqlite ×1
xcode ×1