I'm having problems with NSMutableArray. I am sure that I am doing something wrong with the NSMutableArray distribution, but it is not obvious that I am new to the iPhone. When I run the code below, I can add the MyObject object to the array_ objects and set a name, etc. NSLog displays the correct data.
But when I try to access the objects_ member from the printObject function, I get SIGABRT. Looks like the memory has been freed or something else?
Any help was appreciated.
@interface MyObject : NSObject { NSString *name; } -(void) SetName:(NSString*) name_str; -(NSString*) GetName; @end @interface ObjectListViewController : UITableViewController { NSMutableArray* objects_; } -(void) initTableData; @end @implementation ObjectListViewController - (void)initTableData { objects_ = [[NSMutableArray alloc] initWithCapacity:10]; MyObject *obj = [MyObject alloc]; [obj SetName:@"Test"]; [objects_ addObject:obj]; MyObject* testObj = (MyObject*)[objects_ objectAtIndex:0]; NSLog([testObj GetName]); } - (void)printObject { MyObject* testObj = (MyObject*)[objects_ objectAtIndex:0]; NSLog([testObj GetName]); }
init MyObject , . init NSObject self, . , :
, . init, NSObject, ; self.
Chuck , init , , MyObject.
, . , objects_ . , , , , .
, , printObject @interface. eykanal , printObject , .
, . _ initTableData , MyObject . , - , ?
, objectAtIndex? ? ?
MyObject *obj = [MyObject alloc];
:
MyObject *obj = [[MyObject alloc] init];
@interface ObjectListViewController : UITableViewController { NSMutableArray* objects_; } @property (nonatomic, retain) NSMutableArray *objects_; -(void) initTableData; -(void) printObject; @end
@implementation ObjectListViewController @synthesize objects_;
NSLog(someStringVariable)
NSLog(@"%@", someStringVariable)
Having said all this, I do not see anything that could cause a specific problem. It is possible that the getter or setter for the name in MyObject is incorrect. Please post them.
Source: https://habr.com/ru/post/1763534/More articles:Search Facebook Graph API with OR statments - facebookкак собирать данные определенного типа с помощью рубиновых скриптов - rubyWhy is printf printing wrong values? - cизменение сортировки базы данных SQL Server - sql-serverBest data type for storing rows in SQL Server? - sqlCSS. Можно ли изменить размер фонового изображения, изменив ширину и высоту? - cssUnexpected end of file - linuxNHibernate AND'ing dynamic Disjunction - nhibernateUniform image gallery space - htmlHow ASP.NET knows previous input when submitting a form - c #All Articles