我是stackoverflow的新人:)但我认为,这是问我问题的正确位置.我是Cocoa和Objective-c的新开发人员,我正在尝试编写我的第一个Mac应用程序:ToDo应用程序.
此时,我可以保存ToDo并删除它们,但现在,我想添加一些功能,如CreationDate,一些标签(在mutablearray中),以及ToDo是否完成.我没有使用ArrayController,我将编码的NSMutableArray保存到文件(库/应用程序支持/ AppName)并从那里读取它.
这一切都必须在一行,因为它看起来像这样:
目前的外观http://img683.imageshack.us/img683/7595/bild2ss.png
其中Title应该是ToDo的内容,Blue Box应该是Status(Blue = undone,Gray = Done),Subtitle应该是Date和Tags(03.01.2009 - tag1,tag2) ,tag3)
我现在如何将addObjects添加到mutablearray中,但是,如果我想将所有这4个信息保存到这个数组中,我不知道如何制作它.
我有一个模型,正在初始化这4个信息,但如何保存?我必须在一个数组和我的mutablearray中的数组中保存这个信息吗?
如果我声明一个NSArray与alloc&retain在单句然后我应该释放该NSArray对象两次(即[arrayObject release]2倍)?
我正在尝试向此NSArray(labelArray)添加对象,但由于某种原因,它每次都在NSLog中返回为(null),并且计数保持为0.
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(howFarAlong, howFarDown, 50, 70)];
label.text = @"text";
[self.view addSubview:label];
[labelArray addObject:label];
NSLog(@"%@", labelArray);
[label release];
Run Code Online (Sandbox Code Playgroud) 我有一个NSArray对象,它有一个属性id.
然后,我有另一个NSArray与选择的ID.
我需要获取第一个数组中的所有对象,这些对象在第二个数组中列出了id.
是否可以在没有for循环的情况下执行此操作(对于循环来说好1,但我想避免它).我知道如何用2 for循环来做这个,但这看起来非常低效.所以基本上我正在寻找最有效的方式.
(Id是一个NSURL顺便说一句,所以它不能是任何整数特定的)
我需要一种方法来计算对象在任何给定的MutableArray中出现的次数,然后将对象的索引返回到一个单独的Mutable Array中.香港专业教育学院尝试过这种方式,但无法弄明白.
所以基本上说我有一个包含2,3,3,4,3,5,3的数组当搜索3时,它应该给我两次,4和一个包含1,2,4,6的单独数组(对象的索引.
我在网站上看到了以下代码,但无法解决如何修改它,任何人都可以帮助我吗?
int occurrences = 0;
for(NSString *string in array){
occurrences += ([string isEqualToString:@"Apple"]?1:0); //certain object is @"Apple"
}
Run Code Online (Sandbox Code Playgroud) 我想通过使用NSMutableArray分配NSInteger有没有办法解决这个问题?它不适用于模拟器并在运行应用程序时切断.
NSInteger Section;
NSMutableArray dataSourceSection;
Section = (NSInteger)[dataSourceSection objectAtIndex:2];
Run Code Online (Sandbox Code Playgroud)
谢谢.
我正在使用JSONModel从URL获取JSON.这是一个非常简单的对象,只包含2个字符串 - "name"和"url".
首先我制作了对象模型:
@protocol
Tutorial
@end
@interface Tutorial : JSONModel
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *url;
@end
Run Code Online (Sandbox Code Playgroud)
然后对象Feed:
#import "JSONModel.h"
#import "Tutorial.h"
@interface TutorialFeed : JSONModel
@property (nonatomic, strong) NSArray <Tutorial> *tutorials;
@end
Run Code Online (Sandbox Code Playgroud)
然后在MasterViewController.m中:
#import "MasterViewController.h"
#import "DetailViewController.h"
#import "TutorialFeed.h"
#import "JSONModelLib.h"
@interface MasterViewController () {
TutorialFeed *feed;
TutorialFeed *testFeed;
}
@end
@implementation MasterViewController
-(void)viewDidAppear:(BOOL)animated
{
feed = [[TutorialFeed alloc]
initFromURLWithString:@"http://api.matematikfessor.dk/apps/teacher_videos"
completion:^(JSONModel *model, JSONModelError *err) {
NSLog(@"Tutorials %@", feed.tutorials);
}];
}
@end
Run Code Online (Sandbox Code Playgroud)
问题是,我在日志中返回nil :(我不知道为什么会发生这种情况,因为我设法从这个URL获取JSON数据: Kiwa …
我有一个NSArray的NSDictionaries,在NSDictionary我有叫其保存为"ROWID"的元素NSString,但是一切都保存在它是一个数字..但仍然是一个字符串值.
我想知道如何根据这个值对数组进行排序,但是在排序1-100方面,目前当我对它进行排序时,它首先出现....当它应该是1-10时.
这就是我的排序方式.
NSArray *tempSortedItemsArray = [itemArray sortedArrayUsingDescriptors:
@[[NSSortDescriptor
sortDescriptorWithKey:@"rowID" ascending:YES]]];
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
我已经找过其他类似的帖子了,但没有一个能解决我的问题.我收到此错误:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 19 beyond bounds [0 .. 18]'
Run Code Online (Sandbox Code Playgroud)
我正在使用Searchbar和Display Controller从PARSE.COM数据库获取数据.
这是我的代码:
#import "busquedaViewController.h"
@interface busquedaViewController ()
@end
@implementation busquedaViewController
@synthesize totaldetalles;
@synthesize resultados;
@synthesize busquedaTableView;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display …Run Code Online (Sandbox Code Playgroud) 我希望不需要在这里使用NSMutableArray.我有一个包含10个元素的数组.我想更改索引4处的值.有没有办法在不使用NSMutableArray的情况下执行此操作?NSMutableArray的问题是我们可以改变它的任何内容,包括它的大小.我不希望这个数组的大小意外改变.我只想将索引4的值从22改为25.我怎么能这样做?做array[4]=25不行.
nsarray ×10
objective-c ×8
ios ×3
iphone ×3
cocoa ×2
arrays ×1
cocoa-touch ×1
ios4 ×1
ipad ×1
json ×1
jsonmodel ×1
nsdictionary ×1
nsexception ×1
nspredicate ×1
nstableview ×1
searchbar ×1