nsmutablearray

How to access/print an NSMutableArray element from one view to another view?

烈酒焚心 提交于 2019-12-02 05:29:38
I have an NSMutableArray named mArray in view1 and it stores some strings. Now I want to access/print/compare these elements in view2 . Please guide me. write property synthesize for marray in view1 class.Then create view1 object in the view2 and use as view1object.marray Suggestion: You could put the array in your Controller class,where they both could access. It is always better to have sharable data in Controller then views if data has to be shared among views. view1.mArray should do it. Pls note to @synthesize the mArray in view1 . To print the array in console NSLog(@"mArray from view 1

how to remove duplicate value in NSMutableArray

这一生的挚爱 提交于 2019-12-02 05:13:29
i'm scanning wifi info using NSMutableArray, but there are few duplicate values appear, so i try to use following code but still getting the duplicate values, if([scan_networks count] > 0) { NSArray *uniqueNetwork = [[NSMutableArray alloc] initWithArray:[[NSSet setWithArray:scan_networks] allObjects]]; [scan_networks removeAllObjects]; NSSortDescriptor *networkName = [[[NSSortDescriptor alloc] initWithKey:@"SSID_STR" ascending:YES] autorelease]; NSArray *descriptors = [NSArray arrayWithObjects:networkName,nil]; [scan_networks addObjectsFromArray:[uniqueNetwork sortedArrayUsingDescriptors

Add object to NSMutableArray from other class

自作多情 提交于 2019-12-02 05:10:55
问题 I have a view controller class called PresidentsViewController that sets up data in a UITableView . This data is in the form of NSMutableArray called list . I have another class, PresidentAddController , that is supposed to handle adding an object of type President to this list based on user inputted data about a president. However, I can't get the object to add to the list. I have confirmed that the user inputted data for a new president is being collected correctly, so it is adding to the

UITableview , dynamically section & rows

我的梦境 提交于 2019-12-02 05:07:34
want create a uitableview dynamically with 2 rows in one section i write this code but i have problem the repeats only 2 first rows in all sections now i have this row 0,1 -> section 0 , row 0,1 -> section 1 , row 0,1 -> section 2 want read all rows after for example row 0,1 -> section 0 , row 2,3 -> section 1 , row 4,5 -> section 2 -> row 6,7 items = [[NSMutableArray alloc] init]; - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return items.count/2; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 2; } - (UITableViewCell *

NSMutableArray indexOfObject returning an extremely large number

半世苍凉 提交于 2019-12-02 04:46:03
问题 I have an NSMutableArray returning an extremely large index? po [masterArray count] < returns "2" NSUInteger theIndex = [masterArray indexOfObject:validateEnrollmentStatus]; The above returns an NSUInteger of "2147483647"? I am not sure how that is possible or what is going on? masterArray clearly on has to item in given the count method call in the debug console. Anyone have any suggestions? 回答1: That's the value for NSNotFound . This means the object you are looking for isn't in the array.

Swift NSMutableArray add one more array

北战南征 提交于 2019-12-02 04:17:16
问题 The Problem is First time I get data from WebServices so I have show this data on TableView Then user scroller down tableview then again call WebSevices and add this data to again in array but when I try to add data again in nsmutable type array app is crashing Here is my code. Any solution? 1st time Data load is Working var ary_mutable: NSMutableArray! ary_mutable = NSMutableArray() ary_mutable=jsonResult as AnyObject as! NSMutableArray self.tbl_T.reloadData(); self.tbl_T.delegate=self; self

Does lastObject in NSMutableArray return a copy of the object?

跟風遠走 提交于 2019-12-02 01:30:24
问题 I have a question related to this piece of code NSNumber *lastObject = [self.myStack lastObject]; if(lastObject){ [self.myStack removeLastObject]; } return [lastObject doubleValue]; I am surprised that the lastObject is still in memory despite getting removed. How is this happening? Is it that lastObject returns a copy of the object? 回答1: No, it's not a copy, it's just autoreleased. It will be released in the near future. EDIT: to clarify - on [self.myStack removeLastObject] , the object is

Swift NSMutableArray add one more array

吃可爱长大的小学妹 提交于 2019-12-02 01:02:52
The Problem is First time I get data from WebServices so I have show this data on TableView Then user scroller down tableview then again call WebSevices and add this data to again in array but when I try to add data again in nsmutable type array app is crashing Here is my code. Any solution? 1st time Data load is Working var ary_mutable: NSMutableArray! ary_mutable = NSMutableArray() ary_mutable=jsonResult as AnyObject as! NSMutableArray self.tbl_T.reloadData(); self.tbl_T.delegate=self; self.tbl_T.dataSource=self; 2nd Time data load and add with old array not Working var myArray :NSArray!

NSMutableArray indexOfObject returning an extremely large number

安稳与你 提交于 2019-12-02 00:31:52
I have an NSMutableArray returning an extremely large index? po [masterArray count] < returns "2" NSUInteger theIndex = [masterArray indexOfObject:validateEnrollmentStatus]; The above returns an NSUInteger of "2147483647"? I am not sure how that is possible or what is going on? masterArray clearly on has to item in given the count method call in the debug console. Anyone have any suggestions? That's the value for NSNotFound . This means the object you are looking for isn't in the array. Try it like this. validateEnrollmentStatus is not present in masterArray . So you can probably add a check

Is it correct to use short syntax when initializing NSMutableArray?

早过忘川 提交于 2019-12-02 00:06:36
Usually when we want to initialize NSMutableArray we use: NSMutableArray *mArr = [[NSMutableArray alloc] initWithObjects: @"one", @"two", @"three", nil]; But, is it correct to use syntax like: NSMutableArray *mArr = @[@"one", @"two", @"three"].mutableCopy; I understand, that it will work a couple of nanoseconds longer. But I think the second way to be way more readable and I'm ready to sacrifice those nanoseconds. Is it ok, to use this kind of construction? Does ARC clean that unused NSArray, that I'm using to get a mutable copy? Isn't it going to be a leak? But I think the second way to be