我有一个自定义类"人".
已创建多个Person对象并将其添加到名为"personArray"的NSMutableArray中.
然后我将其中一个传递给下一个视图,称为userView.
这些都已分配和初始化.
我使用的代码是:
[userView setPerson:[personArray objectAtIndex:indexPath.row]];
Run Code Online (Sandbox Code Playgroud)
单击表格行时应用程序崩溃,在调试器中显示:
Loading program into debugger…
GNU gdb 6.3.50-20050815 (Apple version gdb-960) (Sun May 18 18:38:33 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured …Run Code Online (Sandbox Code Playgroud) 我得到的错误是
Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <CALayerArray: 0x7c85080> was mutated while being enumerated.'
Run Code Online (Sandbox Code Playgroud)
我理解的NSGenericException是,我在枚举时从数组中删除了一些东西.仍然知道并环顾四周我似乎无法解决我的问题.这是下面的代码.
-(void)tableView(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//Checks if message has been read. If message has not it updates the unreadMessages array
if ([unreadMessage containsObject:[NSString stringWithFormat:@"m%@",[[storage_array objectAtIndex:indexPath.row] objectForKey:@"id"]]] == TRUE && [[[storage_array objectAtIndex:indexPath.row] objectForKey:@"itemtype"] isEqualToString:@"message"] == TRUE){
//Unread
[unreadMessage removeObject:[NSString stringWithFormat:@"m%@",[[storage_array objectAtIndex:indexPath.row] objectForKey:@"id"]]];
[unreadMessage writeToFile:[self saveUnreadMessages] atomically:YES];
//Read
[readMessage addObject:[NSString stringWithFormat:@"m%@",[[storage_array objectAtIndex:indexPath.row] objectForKey:@"id"]]];
[readMessage writeToFile:[self saveReadMessages] atomically:YES];
[tableView reloadData];
}
else if …Run Code Online (Sandbox Code Playgroud) for (XMLProductView *pV in entries) {
NSString *test = pV.appName;
[allTableData addObject:test];
NSLog(@"Entries: %@", allTableData);
}
Run Code Online (Sandbox Code Playgroud)
在我,NSString *test我得到所有结果.为什么会出现NSMutableArray'allTableData' Null?
请看一下我的代码.我试图将一些Car对象添加到MutableArray*parkPlace(属性属于Park类)
我期待的结果应如下所示:
CarParkSim[2662:303] Parking: Car Number:1 At:3 o'clok Position:0
CarParkSim[2662:303] Parking: Car Number:2 At:4 o'clok Position:1
CarParkSim[2662:303] Parking: Car Number:3 At:5 o'clok Position:2
Run Code Online (Sandbox Code Playgroud)
但是,我得到的实际结果是这样的:
2012-12-22 12:13:46.085 CarParkSim[2662:303] Parking: Car Number:1 At:3 o'clok Position:0
2012-12-22 12:13:46.087 CarParkSim[2662:303] Parking: Car Number:2 At:4 o'clok Position:0
2012-12-22 12:13:46.088 CarParkSim[2662:303] Parking: Car Number:3 At:5 o'clok Position:0
Run Code Online (Sandbox Code Playgroud)
我确实检查了NSmutablearray,它是空的......似乎把任何东西都推到了堆栈......任何建议?谢谢
无论如何,这里是代码:Park类:
#import <Foundation/Foundation.h>
#import "Stack.h"
#import "Car.h"
@interface Park : NSObject
@property(strong,nonatomic)NSMutableArray *parkPlace;
@property(strong,nonatomic)Car *car;
-(void)carMoveIntoPark:(Car *)car;
@end
#import "Park.h"
@implementation Park
-(void)carMoveIntoPark:(Car *)car
{
if ([self.parkPlace count] …Run Code Online (Sandbox Code Playgroud) 所以我想知道当我这样做会发生什么
NSMutableArray *arr1 = [[NSMutableArray alloc] init];
NSMutableArray *arr2 = [[NSMutableArray alloc] init];
[arr1 addobject:ob1];
arr2 = arr1;
[self changeValue:[arr2 objectAtIndex:2]]; //function that will modify what is sent to it
Run Code Online (Sandbox Code Playgroud)
1)我甚至可以在nsmutablearrays之间进行操作吗?
2)如果我要访问arr1中的对象,是否会被修改?
3)它有多深? - 如果我要从其他地方访问该对象,是否会被修改?
4)我假设使用mutableCopy将返回一个全新的数组.
5)无论如何都要模拟这种深层连接/连接?例如,如果我想将同一个对象分配给2个不同的数组,那么如果我修改了一个,那么它会改变两个数组中的那个对象吗?
6)这个词代表什么?我不认为它是连接/连接.
非常感谢
- 詹姆斯
我只是试图在这两个类之间传递一个NSArray,每当我在B类中NSLog它的值时它返回NIL.
为什么这样,我如何让它显示到这个UITableView?
这是Class Ah
#import <UIKit/UIKit.h>
#import "Class B.h"
@class Class B;
@interface Class A : UIViewController <UITableViewDataSource, UITableViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate, UIPopoverControllerDelegate> {
IBOutlet UITableView *ToolsTable;
IBOutlet UICollectionView *strategyCollection;
IBOutlet UIButton *countButton;
IBOutlet UIButton *camerButton;
IBOutlet UIButton *videoButton;
IBOutlet UIButton *textButton;
IBOutlet UIButton *probeButton;
IBOutlet STPopOverQuestionViewViewController *questionListController;
IBOutlet UIPopoverController *questionList;
NSMutableDictionary *stratToolsDict;
NSMutableArray *stratTools;
NSMutableArray *stratObjects;
NSMutableDictionary *QuestionDict;
NSMutableArray *QuestionsList;
}
@property (strong, nonatomic) IBOutlet UIView *strategyOBJView;
@property (retain, nonatomic) NSMutableDictionary *stratToolsDict;
@property (retain, nonatomic) NSMutableArray *stratTools;
@property (retain, nonatomic) …Run Code Online (Sandbox Code Playgroud) 我以为这个计数会返回26,但它会返回零.az是未初始化的UIImageViews.你现在问题可能是什么?
NSMutableArray *letters = [[NSMutableArray alloc]initWithObjects: a,b,c,d,e,f,g,self.h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z, nil];
NSLog(@"%d",(int)[letters count]);
Run Code Online (Sandbox Code Playgroud) 当我尝试将nsarray对象插入到可变的swift数组时,我得到了这个控制台输出.代码工作正常,但最后,它抛出一个错误.请帮我解决这个错误.
Successfully retrieved 3 scores.
Optional("HmEbbowtxW")
<Events: 0x7b08bdf0, objectId: HmEbbowtxW, localId: (null)> {
CreatedBy = "<PFUser: 0x7b02ed10, objectId: 04jp1ZeBn6>";
EventDescription = test;
EventName = test;
}
Optional("97BzKUxFdE")
<Events: 0x7b08cae0, objectId: 97BzKUxFdE, localId: (null)> {
CreatedBy = "<PFUser: 0x7b02ed10, objectId: 04jp1ZeBn6>";
EventDescription = fg;
EventName = gfg;
}
Optional("QDHkg5tiUw")
<Events: 0x7b08cf80, objectId: QDHkg5tiUw, localId: (null)> {
CreatedBy = "<PFUser: 0x7b02ed10, objectId: 04jp1ZeBn6>";
EventDescription = asdasdasd;
EventName = sdsd;
}
Could not cast value of type '__NSArrayI' (0x228e164) to 'NSMutableArray' (0x228e1c8).Run Code Online (Sandbox Code Playgroud)
这是我的代码 …
如何将自定义类对象附加到Swift中的数组?下面是我的代码,但它显示错误.
错误:
"无法指定'()'的值来输入[PhotoVC]"
码:
var photoVCs = [PhotoVC]()
for index in 0 ..< photos.count {
if let vc = getPhotoController(index) {
photoVCs = photoVCs.append(vc)
}
}
func getPhotoController(index: Int) -> PhotoVC? {
if index < 0 || index == NSNotFound {
return nil
}
else if index == photos.count {
return nil
}
let PhotoVCID = "PhotoVCID"
if let storyboard = storyboard,
pageVC = storyboard.instantiateViewControllerWithIdentifier(PhotoVCID) as? PhotoVC {
pageVC.photoName = photos[index]
pageVC.photoIndex = index
return pageVC
}
return nil
} …Run Code Online (Sandbox Code Playgroud) 我不小心将手机中的iOS版本从10.3.3更新到了11.0.3。因此,我不得不将xcode升级到最新的9.1版本。现在,当我在xcode 9.1中运行代码时,
无法将类型“ Swift._ContiguousArrayStorage”的值转换为“ NSMutableArray”
似乎不再有从“ AnyObject”数组到“ NSMutableArray”的转换。但是我在整个代码中都使用了这种转换。我花了将近一天的时间尝试使用[[String:AnyObject]]而不是[AnyObject],这不是一个好主意,因为它会影响整个代码,并且感觉就像我从头开始重新编写代码。任何人都可以提出更好的解决方案。
nsmutablearray ×10
objective-c ×6
ios ×4
swift ×3
cocoa-touch ×2
nsarray ×2
anyobject ×1
arrays ×1
interface ×1
ipad ×1
iphone ×1
object ×1
stack ×1
xcode ×1