我正在讨论NSMutableArray的-removeAllObjects,-removeLastObject等方法.文档只说这些方法'从数组中删除'对象.删除的对象是否已释放?
看起来很容易将一个布尔值添加到NSMutableArray中.
假设toDoArray初始化为NSMutableArray.下列:
BOOL checkBoxState = NO;
[toDoArray addObject:checkBoxState];
Run Code Online (Sandbox Code Playgroud)
生成错误"尝试插入nil".
将负布尔值添加到可变数组的正确方法是什么?
我有一个NSMutableArray包含"N"个对象的实例,我想检查是否NSMutableArray包含(null)或任何其他值.
在NSString有一个方法称为isEqualToString:是否有类似的方法可用NSMutableArray?
或者,我怎么能这样做?
我有一个NSMutableArray,我加载了不同的对象(类).
现在我需要遍历数组并进入类以进行进一步操作.
我正在尝试这种方法......
for (id obj in allPointsArray)
{
///// this is where i need to bring the obj into a class to work with
NSInteger loc_x = obj.x_coord;
NSInteger loc_y = obj.y_coord;
}
Run Code Online (Sandbox Code Playgroud)
但我无法理解实际上将类从数组中移出并将其放入可用对象中.
x_coord和y_coord在存储在数组中的所有对象之间是通用的.
谢谢大家的帮助
我有一个NSMutableArray初始化10个元素.我试图获得一个元素运行异常时出现的问题..
我以这种方式创建数组:
NSMutableArray *selected = [[NSMutableArray alloc] init];
[selected setValue:[NSString stringWithFormat:@"casa_selected.png"]forKey:[NSString stringWithFormat:@"%d",1]];
[selected setValue:[NSString stringWithFormat:@"chiave_selected.png"]forKey:[NSString stringWithFormat:@"%d",2]];
[selected setValue:[NSString stringWithFormat:@"gatto_selected.png"]forKey:[NSString stringWithFormat:@"%d",3]];
[selected setValue:[NSString stringWithFormat:@"giacca_selected.png"]forKey:[NSString stringWithFormat:@"%d",4]];
[selected setValue:[NSString stringWithFormat:@"nonno_selected.png"]forKey:[NSString stringWithFormat:@"%d",5]];
[selected setValue:[NSString stringWithFormat:@"lumaca_selected.png"]forKey:[NSString stringWithFormat:@"%d",6]];
[selected setValue:[NSString stringWithFormat:@"cane_selected.png"]forKey:[NSString stringWithFormat:@"%d",7]];
[selected setValue:[NSString stringWithFormat:@"occhiali_selected.png"]forKey:[NSString stringWithFormat:@"%d",8]];
[selected setValue:[NSString stringWithFormat:@"portafogli_selected.png"]forKey:[NSString stringWithFormat:@"%d",9]];
[selected setValue:[NSString stringWithFormat:@"telecomando_selected.png"]forKey:[NSString stringWithFormat:@"%d",10]];
Run Code Online (Sandbox Code Playgroud)
当我尝试获取元素时:
[selected valueForKey:[NSString stringWithFormat:@"%d",2]]
Run Code Online (Sandbox Code Playgroud)
它运行此异常:
2011-11-05 10:04:37.426 TrovaChiavi[22307:11f03] -[__NSArrayI isEqualToString:]:
unrecognized selector sent to instance 0x78317b0
2011-11-05 10:04:37.494 TrovaChiavi[22307:11f03] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '-[__NSArrayI isEqualToString:]:
unrecognized selector …Run Code Online (Sandbox Code Playgroud) 我是IOS开发的新手,我正在尝试开发我的第一个应用程序.
所以我的问题是......我有一个带有自定义单元格的UITableView,每个单元格都包含一个UITextField.当我按下一个按钮时,我想将每个UITextField值放在NSMutableArray中.
我想我必须做那样的事情,但我不确定:
NSMutableArray *playerNameArray = [[NSMutableArray alloc] init];
for (int i=0; i < nbPlayers; i++){ //nbPlayers is the number of rows in the UITableView
NSString *playerName =UITextField.text;
[playerNameArray addObject:[NSString stringWithFormat: @"%@", playerName]];
}
Run Code Online (Sandbox Code Playgroud)
如果有人可以帮助我.... :)谢谢
我想创建自己的自定义对象NSMutableArray:
@interface Course : NSObject {
NSString *className;
NSString *classGrade;
NSInteger creditHours;
}
Run Code Online (Sandbox Code Playgroud)
这个类将存储一系列课程:
@interface AllCourses : NSObject : NSMutableArray{
NSMutableArray *arrClasses;
}
Run Code Online (Sandbox Code Playgroud)
我希望"AllCourses"继承自NSMutableArray,所以我可以像任何其他NSMutableArray对象一样使用它,并从中添加\ remove课程并将其加载到tableView等...所以我的问题是,如果你会这么善良,是我对"AllCourses"的实现应该是什么样的?
我正在尝试通过for循环将对象添加到NSMutableArray.但似乎每当我添加一个对象时它会替换旧的对象,这样我当时在数组中只有一个对象......
你知道什么可能是错的吗?
- (void)viewDidLoad
{
[super viewDidLoad];
LoginInfo *info = [[LoginInfo alloc] init];
info.startPost = @"0";
info.numberOfPosts = @"10";
info.postType = @"1";
getResults = [backendService getAllPosts:info];
for (NSInteger i = 0; i < [getResults count]; i++) {
Post *postInfo = [[Post alloc] init];
postInfo = [getResults objectAtIndex:i];
dataArray = [[NSMutableArray alloc] init];
[dataArray addObject:postInfo.noteText];
NSLog(@"RESULT TEST %@", dataArray);
}
}
Run Code Online (Sandbox Code Playgroud)
这是RESULT TEST日志,它始终只显示输出中最后添加的字符串.
我有一个NSMutableArray自定义对象(基于NSObject),我想复制到一个新的数组.但我希望它是一个深刻的副本.
我该怎么做呢?我是否需要在自定义对象中实现NSCopying协议?
谢谢
我NSMutableArray包含一些字符串作为元素.其中一个元素在数组中的不同索引处重复多次.例如[@"", @"1,2,3",@"",@"5,3,2,1",@""].我想@""从可变数组中删除所有带有值的元素.我尝试了以下方法,但无法得到解决方案.
使用For循环:
for(id obj in myMutableArray)
{
if([obj isEqualToString:@""])
{
[myMytableArray removeObject:obj];
}
}
Run Code Online (Sandbox Code Playgroud)使用虚拟可变数组调用 nextMutableArray
for(id obj in myMutableArray)
{
if([obj isEqualToString:@""])
{
continue;
}
else [nextMutableArray addObject:obj];
}
Run Code Online (Sandbox Code Playgroud)在这两种方式中,@""其他索引的elements()被删除但不在索引0(第一个对象).可能的原因是什么?有没有办法@""从可变数组中删除包含字符串的所有元素?
nsmutablearray ×10
objective-c ×7
ios ×3
iphone ×3
nsarray ×2
boolean ×1
cocoa ×1
copy ×1
deep-copy ×1
exception ×1
nsobject ×1
uikit ×1
uitableview ×1
uitextfield ×1