我正在尝试复制NSMutableArray到另一个但它没有向我显示任何内容UITableView:
NSMutableArray *objectsToAdd= [[NSMutableArray alloc] initWithObjects:@"one",@"two"];
NSMutableArray *myArray = [[NSMutableArray alloc] initWithObjects:objectsToAdd,nil];
NSMutableArray *list = [[NSMutableArray alloc] init];
[self.list addObjectsFromArray:myArray];
Run Code Online (Sandbox Code Playgroud)
什么都没有出现!怎么了?
它崩溃了我的应用程序,因为我没有对我的nil NSMutableArray如何添加nil?addobject:nil不起作用它崩溃的应用程序:
static NSString * DisclosureButtonCellIdentifier =
@"DisclosureButtonCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
DisclosureButtonCellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier: DisclosureButtonCellIdentifier]
autorelease];
}
NSUInteger row = [indexPath row];
NSString *rowString =nil;
rowString = [list objectAtIndex:row];
cell.textLabel.text = rowString;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
[rowString release];
return cell;
Run Code Online (Sandbox Code Playgroud) 如何在Objective-C中的特定索引处打印数组元素?我的代码看起来像这样:
NSString *String=[NSString StringWithContentsOFFile:@"/User/Home/myFile.doc"];
NSString *separator = @"\n";
NSArray *array = [String componetntsSeparatedByString:separator];
NSLog(@"%@",array);
Run Code Online (Sandbox Code Playgroud)
我能够一次打印一个数组的全部内容,但我想将每个索引处的元素分配给一个字符串,比如......
str1=array[0];
str2=array[1];
str3=array[0];...this continues
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?
工作妨碍了学习目标C,但我现在又回到了它,这让我发疯了.
这是我的代码:
i=0;
for (i=0;[photoList count]; i++) {
NSLog(@"%i",i);
NSLog(@"%@",[photoList objectAtIndex:i]);
NSString *fileName = [photoList objectAtIndex:i];
sendImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:nil]];
UIImageWriteToSavedPhotosAlbum(sendImage,self,@selector(savedPhotoImage:didFinishSavingWithError:contextInfo:),NULL);}
Run Code Online (Sandbox Code Playgroud)
photoList只是一个NSArray,只有24个对象:
NSArray* photoList = [NSArray arrayWithObjects:@"Photo 1.jpg",
@"Photo 2.jpg",
@"Photo 3.jpg",
@"Photo 4.jpg",nil];
Run Code Online (Sandbox Code Playgroud)
它有效...它将照片复制到相机胶卷......然后崩溃
2010-07-24 19:34:36.116 iCardz2go Poindexter [29662:207] *由于未捕获的异常'NSRangeException'终止应用程序,原因:'* - [NSArray objectAtIndex:]:索引24超出边界[0 .. 23]'
我尝试了各种配置,比如
for (i=0;1<23; i++)
Run Code Online (Sandbox Code Playgroud)
只能得到2010-07-24 19:51:01.017 iCardz2go Poindexter [29908:207]***由于未捕获的异常'NSInvalidArgumentException'终止app,原因:'+ [NSInvocation invocationWithMethodSignature:]:方法签名参数不能为nil'
所以它正在读取零并传递它.
我知道它会变得非常简单,我已经忘记了.为什么不跳出照片23(计数)的循环?
非常感谢您的帮助!P
我正在开发一款需要单屏平面图的基本iPhone游戏.那里没什么难的.我来自C背景,所以我目前的解决方案看起来有点像这样:
typedef struct _Tile {
NSString *type;
} Tile;
@interface Map {
Tile mapData[MAP_TILE_MAX_X][MAP_TILE_MAX_Y];
}
Run Code Online (Sandbox Code Playgroud)
这很好,但我想知道是否有一种更"正确"的方式来处理Objective-C的事情.如果我采用Objective-C方法,我会看到情况如何:我将创建一个基本的Tile类来保存基本的tile属性,然后我可以为特定的tile类型(@interface Water : Tile {}例如)创建子类.这将允许我也具有特定于Tile的逻辑.例如:Tile类可以有一个'think'方法来执行任何必要的逻辑.在我的Water子类中,如果玩家被淹没,这可能会产生涟漪效应.
我的问题是:
我有一个表视图,其数据源来自包含人名的数组.
现在为了方便查找人员,我想分区表视图,使其右侧有字母AZ,就像地址簿应用程序一样.
但我当前的数组只包含一个集合NSStrings.如何拆分它们以便按名称的第一个字母分组?有没有方便的方法呢?
编辑:如果有人对我的最终代码感兴趣:
NSMutableArray *arrayChars = [[NSMutableArray alloc] init];
for (char i = 'A'; i <= 'Z' ; i++) {
NSMutableDictionary *characterDict = [[NSMutableDictionary alloc]init];
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
for (int k = 0; k < [myList count]; k++) {
NSString *currentName = [[friends objectAtIndex:k] objectForKey:@"name"];
char heading = [currentName characterAtIndex:0];
heading = toupper(heading);
if (heading == i) {
[tempArray addObject:[friends objectAtIndex:k]];
}
}
[characterDict setObject:tempArray forKey:@"rowValues"];
[characterDict setObject:[NSString stringWithFormat:@"%c",i] forKey:@"headerTitle"];
[arrayChars addObject:characterDict];
[characterDict …Run Code Online (Sandbox Code Playgroud) 我有一个UIImageView作为我的tabbarcontroller视图之一,我添加了一个UISwipeGestureRecognizer(左右)来浏览NSArray中的一系列照片.
但是,在滑动时,它会从照片跳转到照片而没有平滑过渡.我不喜欢任何花哨的东西,但即使是幻灯片动画也没关系,就像一张照片滑入,另一张滑出另一边.这可能与UISwipeGestureRecgonizer和NSArray一起使用吗?
我试图从Array.But创建一个字符串,有如何生成它的条件,如下所述.
NSArray *array=[NSArray arrayWithObjects:@"Hello",@"World",nil];
[array componentsJoinedByString:@","];
Run Code Online (Sandbox Code Playgroud)
这将输出:Hello,World.
但是,如果第一项是空的,那么是否有办法接收唯一的第二项.
我有一个A类对象的数组,让它成为detailsArray.
A类具有日期,名称为属性.
任何人都可以提出一个基于日期对这个数组进行排序的好方法吗?
我如何使用NSSortDescriptor这个数组排序?我知道使用NSSortDescriptor... 排序字典数组
任何帮助是极大的赞赏.....
我想允许不同观点之间的沟通.
我有两个较小的视图,位于更大的视图之上,类似于iOS的视频播放器,但有一些差异.当我点击较大的视图时,我想要切换视图外观,隐藏或取消隐藏.我有一个所有视图都符合的协议.我想将视图添加到我将调用的另一个类中,该类HideViewsService具有NSArray属性.我可以强制使用此类的HideViewsService类,并添加视图,以仅添加符合此协议的视图吗?甚至只是UIViews?
另外,我想在我知道所有的视图上调用一个方法,但我不知道如何通过编译器获取.这是我的-hideAllViews方法:
-(void)hideAllViews
{
for(int i=0; i<self.viewArray.count; i++)
{
id obj = [self.viewArray objectAtIndex:i];
if([obj isKindOfClass:[UIView class]] == false)
{
return;
}
UIView *view = (UIView *)obj;
if([view respondsToSelector:@selector(hide)])
{
[view hide]; // the compiler obviously doesn't like this
}
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢!!我还在学习,所以请告诉我是否有更好的方法(不仅更容易,而且更好).
var cellHeights: [CGFloat] = [CGFloat]()
if let height = self.cellHeights[index] as? CGFloat {
self.cellHeights[index] = cell.frame.size.height
} else {
self.cellHeights.append(cell.frame.size.height)
}
Run Code Online (Sandbox Code Playgroud)
我需要检查指定索引处的元素是否存在.但是上面的代码不起作用,我得到了构建错误:
从CGFloat到CGFloat的条件下转总是成功的
我也尝试过:
if let height = self.cellHeights[index] {}
Run Code Online (Sandbox Code Playgroud)
但这也失败了:
Bound value in a conditional binding must be of Optional type
Run Code Online (Sandbox Code Playgroud)
任何想法都错了吗?
nsarray ×10
objective-c ×6
ios ×4
iphone ×4
arrays ×1
cocoa-touch ×1
copy ×1
for-loop ×1
ios4 ×1
nsstring ×1
protocols ×1
struct ×1
swift ×1
swipe ×1
uiimageview ×1
uitableview ×1
xcode ×1