我想从NSMutableArray中获取值,但是想要从最后一个索引读取到第一个索引
谢谢
我正在开发一个应用程序,它将使用自定义图像选择器并尽可能地尝试,我似乎无法让应用程序运行得非常正确.Xcode调试器标记以下"线程1:程序接收信号:"SIGABRT"."
- (id) init {
if ((self = [super init])) {
_images = [[NSMutableArray alloc] init];
_thumbs = [[NSMutableArray alloc] init];
}
return self;
}
- (void)addImage:(UIImage *)image {
[_images addObject:image];
[_thumbs addObject:[image imageByScalingAndCroppingForSize:CGSizeMake(64, 64)]];
}
Run Code Online (Sandbox Code Playgroud)
这是在新调试器的xcode 4中.提前致谢.
我有一个带有以下对象的NSMutableArray:
@interface MyViewCell : UITableViewCell {
NSUInteger id;
.....
}
Run Code Online (Sandbox Code Playgroud)
在某些方法中,我需要快速搜索具有预定义id的单元格.怎么做到最好?
所有,
我有一个存储在NSMutableArray中的字符串.当代码中的其他位置满足某个条件时,NSMutableArray(read,objectAtIndex:0)中FIRST的对象将被删除.删除之后,我需要将所有内容都移到索引中.这是我的例子:
/*
Index/Value
0 - one
1 - two
2 - three
3 - four
4 - five
5 - six
6 - seven
*/
//removes object...
[mArray removeObjectAtIndex:0];
//I am missing something here...
//I want the value of the array to be as follows:
/*
Index/Value
0 - two
1 - three
2 - four
3 - five
4 - six
5 - seven
*/
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
编辑:NSMutableArray存储在NSUserDefaults中.这可能导致这不起作用吗?
EDIT2:因为它存储在NSUserDefaults中,所以它变为不可变.查看接受的答案,了解正确的方法.详细信息:崩溃我的应用程序[NSMutableArray1 removeAllObjects] iphone sdk
有人可以通过循环显示如何检索值NSMutableArray吗?我的代码基本上为数组添加整数,如下所示:
NSMutableArray *ptr = [[NSMutableArray alloc] init];
[ptr addObject:[NSNumber numberWithInt:1]];
[ptr addObject:[NSNumber numberWithInt:2]];
[ptr addObject:[NSNumber numberWithInt:3]];
// How to retrieve them as integers?
Run Code Online (Sandbox Code Playgroud)
我正在尝试从数组中检索每个数字并将它们总计为总值.
我开始在Objective-C中编程.我正在使用一本书来学习第一批基础知识.给出的例子不起作用!我在代码中看不到问题.
理解它并不是那么难,但它不会起作用.但是我在其他地方找到的一切,他们像我一样添加了对象.
我不知道语法是否改变了?我使用的是iOS 4.3 SDK和Xcode 3.2.6!
这部分失败了:
[questions addObject: @”What is 7 + 7?”]; //FAILS
[answers addObject: @”14”];
Run Code Online (Sandbox Code Playgroud)
错误消息显示:
/Applications/Quiz/Classes/QuizAppDelegate.m
:32:0 Applications/Quiz/Classes/QuizAppDelegate.m:32:error:'@'令牌之前的预期表达式
如果有人可以帮助我,我会很高兴!谢谢!
我也附上了代码!
儒勒
完整代码:.h:
#import <UIKit/UIKit.h>
@interface QuizAppDelegate : NSObject <UIApplicationDelegate> {
int currentQuestionIndex;
//The model objects
NSMutableArray *questions;
NSMutableArray *answers;
//The view objects
IBOutlet UILabel *questionField;
IBOutlet UILabel *answerField;
UIWindow *window;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
-(IBAction)showQuestion:(id)sender;
-(IBAction)showAnswer:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)
失败的部分代码:.m:
#import "QuizAppDelegate.h"
@implementation QuizAppDelegate
@synthesize window;
-(id)init{
// Call the init method implemented by the …Run Code Online (Sandbox Code Playgroud) 我是这堂课:
@interface PersonModel : NSObject
@property (nonatomic, weak) NSString *string;
@property (nonatomic, weak) NSMutableArray *array;
@end
Run Code Online (Sandbox Code Playgroud)
在另一个类中,我使用该字符串和数组.字符串很好,但数组变为null.我像往常一样启动它,像这样:
person.array = [[NSMutableArray alloc] init];
[person.array addObject:[object copy]];
NSLog(@"Array: %@", person.array);
Run Code Online (Sandbox Code Playgroud) 非常基本的问题.我需要初始化一个NSMutableArray,其值从1到n(或者说m到n,比如说).有没有我可以做的事情来初始化数组而不使用for循环?我的意思是有什么:
[[NSMutableArray alloc] initWithSomeThing];
提前致谢.
问题:这个过程与iOS6完美配合.现在它不会提取最新信息并替换显示的数据.因此,应用程序信息总是错误的.如果我重置模拟器上的内容,它可以在当前时间段内工作.之后我将需要重新设置内容.有什么建议.我已经包含了处理我所有数据处理的3个文件以供参考.
Reader.M
- (void) startRequest
{
NSURL *url = [[NSURL alloc] initWithString:@"http://www.something.com/app/rss/"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:60.0f];
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES];
if(conn)
{
_receivedData = [[NSMutableData alloc]init];
}
}
#pragma mark - NSURLConnectionDataDelegate
- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"%@",error.description);
}
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(@"received %d bytes",data.length);
[_receivedData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:_receivedData];
JSTRRSSParser *rssParser = [[JSTRRSSParser alloc] init];
parser.delegate = rssParser; …Run Code Online (Sandbox Code Playgroud) 当我尝试使用NSMutableArray对自定义对象进行编码时,我总是会遇到以下异常:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'cannot encode (void *) value: <2063e916>'
Run Code Online (Sandbox Code Playgroud)
什么可能导致这个?mutablearray被初始化,并且在它断开的那一点上有数据.我很确定我在'encodeWithCoder'方法中做错了,因为如果我把它保持为空,它运行良好.
这就是我尝试将我的mutablearray转换为数组的方法,但这没有帮助:
- (void) encodeWithCoder:(NSCoder *)encoder {
[encoder encodeObject:[[NSArray alloc] initWithArray:_myMutableArray] forKey:kMutableArrayKey];
}
Run Code Online (Sandbox Code Playgroud) nsmutablearray ×10
objective-c ×8
ios ×4
cocoa ×2
iphone ×2
add ×1
loops ×1
nsarray ×1
nscoding ×1
nsdictionary ×1
nsnumber ×1
nsxmlparser ×1
null ×1
object ×1
reverse ×1
xcode ×1