我一直在使用NSMutableArray,并且通过使用从数组中检索对象没有任何问题objectAtIndex:int.而不是通过整数将对象拉出数组,这是通过用字符串搜索数组来获取索引位置的一种方法.
animalOptions = [[NSMutableArray alloc] init];
//Add items
[animalOptions addObject:@"Fish"];
[animalOptions addObject:@"Bear"];
[animalOptions addObject:@"Bird"];
[animalOptions addObject:@"Cow"];
[animalOptions addObject:@"Sheep"];
NSString * buttonTitle = [animalOptions objectAtIndex:1];
// RETURNS BEAR
int * objectIndex = [animalOptions object:@"Bear"];
// THIS IS WHAT I NEED HELP WITH, PULLING AN INDEX INTEGER WITH A STRING (ex: Bear)
Run Code Online (Sandbox Code Playgroud)
希望这是有道理的,并且有答案,我无法在线研究并通过谷歌或苹果的课程参考找到任何东西.
我是iphone开发的新手.我想要一个Nsmutable数组来保存从1到100的数字.我能做什么.我可以在for循环中实现.是否还有其他方法可以在iphone中保存数组中的数字.请帮助我出去了.谢谢.
对于基于唯一整数键的数据集,我有一个未确定的大小.
我想使用NSMutableArray快速查找,因为我的所有键都是基于整数的.
我想做这个.
NSMutableArray* data = [NSMutableArray array]; // just create with 0 size
Run Code Online (Sandbox Code Playgroud)
然后人们会开始用整数索引向我扔数据(都是唯一的)所以我只想做这样的事......
if ([data count] < index)
[data resize:index]; // ? how do you resize
Run Code Online (Sandbox Code Playgroud)
并调整数组大小,以便我可以...
[data insertObject:obj atIndex:index];
Run Code Online (Sandbox Code Playgroud)
最后一个尺寸和新尺寸之间的所有槽都为零,最终将在以后填充.
所以我的问题是如何调整现有的大小NSMutableArray?
谢谢,罗马
我有一个NSString : @"1a,1b,1c,1d,5c". 我想将这个NSString分成NSMutableArray,但我不知道如何.我认为这很简单,但我找不到它(也许是因为我的英语不够好,无法找到一个好的描述来搜索).
此致,渡渡鸟
你如何"int"在一个NSMutableArray或多个存储值NSMutableDictionary?JSON数据的慢性问题以整数形式出现.
我应该尝试将这些整数存储为NSNumber对象还是作为包含整数的字符串存储?
如果我知道值将始终为自然数(数字> = 0,包括零为零),那么对指针执行"原始"(int)转换有多危险.
我一直在使用的整数是来自数据库的外键ID.
我想存储两个我在AppDelegate中用作全局数组的NSMutableArray.这两个数组也与NSUserDefaults一起存储.现在我想知道我必须如何创建这个文件,以及每次修改它们时如何存储这两个数组.你能帮助我吗?
我几乎没有看到第二个用过,我想知道为什么?
NSArray预期的情况的支持(因为它是一个子类).在前提条件下,它永远不会是一个可变的ivar返回,(无论如何应该是常识)
我现在只能想到使用第二个的优点.
[[[foo fooBar] mutableCopy] autorelease],不必要地分配额外的内存,不必要地浪费时间.以下是方法变体:
- (NSArray *)fooBar {
NSMutableArray *fooArray = [NSMutableArray array];
//populate fooArray
return fooArray;
}
- (NSMutableArray *)fooBar {
NSMutableArray *fooArray = [NSMutableArray array];
//populate fooArray
return fooArray;
}
Run Code Online (Sandbox Code Playgroud)
我问,因为我的项目有一堆具有相同模式的方法.
并且在大多数情况下,返回的数组将在之后被修改(合并,编辑等).
所以我认为返回应该是完全没问题NSMutableArrays,但似乎没有人这样做.
NSMutableArray,NSMutableSet …
如果我想返回一个像这样的不可变数组+ (NSArray *)ids但是在这个方法中我声明了一个NSMutableArray因为我想用它来排序它-sortUsingSelector:.
返回此方法非常有效.
但编写声明返回方法应该是一种类型而实际类型是另一种类型的代码是否"没问题"?
这是否有效,因为它NSMutableArray是一个子类NSArray?
实际的回报值是一个NSArray还是一个NSMutableArray?
我有这个代码试图在一个循环中运行一组简单的图像.我在应用程序中的所有内容都是在我的View Controller的.h文件中声明的一个UIImageView:
@property (strong, nonatomic) IBOutlet UIImageView *imageDisplay;
Run Code Online (Sandbox Code Playgroud)
以下是我的.m文件的viewDidLoad方法:
NSMutableArray *imageView = [[NSMutableArray alloc] init];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim1.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim2.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim3.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim4.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim5.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim6.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim7.png"]]];
imageDisplay.animationImages = imageView;
imageDisplay.animationDuration = 0.25;
imageDisplay.animationRepeatCount = 50;
[imageDisplay startAnimating];
Run Code Online (Sandbox Code Playgroud)
代码似乎在"imageDisplay.animationImages"行上崩溃,就像我创建UIImageView,创建它的getter和setter,以及构建一样,直到我取消注释该行为止.如果我取消注释它,它会一直给我错误,直到我删除UIImageView并创建一个新的.
不太确定发生了什么,任何帮助表示赞赏!
我有一个学生班:
@interface student : NSObject{
NSString *name;
NSDate *date;
}
Run Code Online (Sandbox Code Playgroud)
我有一个NSMutableArray用于学生列表,我把它绑定到像这样的NSPopUpButton
content:studentArray,arrangeObjects内容值:studentArray,arrangeObjects,name
现在我可以得到这样的学生对象:
-(IBAction)studentPopupItemSelected:(id)sender
{
NSPopUpButton *btn = (NSPopUpButton*)sender;
int index = [btn indexOfSelectedItem];
student *std = [studentArray objectAtIndex:index];
NSLog(@"%@ => %@", [std name], [std date]);
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以直接从NSPopUpButton获取学生对象???? 喜欢:
NSPopUpButton *btn = (NSPopUpButton*)sender;
student *std = (student *)[btn objectValueOfSelectedItem];
Run Code Online (Sandbox Code Playgroud) cocoa objective-c nsmutablearray cocoa-bindings nspopupbutton
nsmutablearray ×10
objective-c ×7
cocoa ×5
cocoa-touch ×2
ios ×2
nsarray ×2
nsnumber ×2
iphone ×1
nsstring ×1
plist ×1
return-type ×1
sigabrt ×1
uiimageview ×1
xcode ×1