I have to 2 NSArray and I merge it into NSMutableArray now I have to distinguish it. How many values in 1 NSArray and 2 also. My problem is that when I got 1 NSArray then I want to show red button before that in table view and 2 array i wnat to show green button. How can i achieve this. I want to show such type of result.
store all values in NSArray as dictionaries with 2 keys - one for the actual object and other for the array type(array1 or array2) and use the same to distinguish the objects in common array
it is better that for combining two array use
NSMutableDictionary rather than NSMutableArray
Related
I have a UITableView and an array for data source of it.
But I don't want to use all objects in the array but some of them.
since I need that array fully later, I don't want neither remove any objects from array nor filter the array with the desired objects.
Any suggestions?
You will have to have two arrays:
1- All items are stored in original array;
2- Second array with indices of the items to show in the table
arrOne[arrSecond[i]]
would be the item number i in the table
You need another array with the list of filtered items.
I have a NSmutableArray like this.
[obj1,obj2,obj3,obj5,......];
this has assigned into a UITableView
lets say user clicked on the 3rd cell. then I need to create another NSMutableArray like this.
[obj3,obj4,obj5,------]; need to remove first few objects from the array upto the current object. How can I do this.
please help me.
Thanks
you can use this...for remove specific object from any mutable array...
[array removeObjectAtIndex:0];
I have a view with UITableView and I populate NSMutableDictionary and bind it to UITableView.
I add items like: c,b,a,d but data in table are displayed like: a,b,c,d.
Is it possible to disable ordering so items will be displayed in table in the same order as I added them in NSMutableDictionary?
If the order objects are displayed in your table view matters, you should be using an NSArray or NSMutableArray. These are the only Objective-C collections for which the order can be guaranteed, and they work a lot easier with table views than any other collections, given that their objects are stored at indexes and these can match exactly to the row portion of the NSIndexPath argument of cellForRowAtIndexPath:.
I have a NSMutableArray when it is added to, removed from, or changes the notifications from the array update my UITableView such that those changes are reflected in the UITableView automatically using KVO observing. This works great.
We now a have a new requirement that we want to filter out certain items from the array. This just shows what kind of filtering I would like to do:
NSIndexSet *indexes = [array indexesOfObjectsPassingTest:
^BOOL(MyObject *obj, NSUInteger idx, BOOL *stop)
{
return !obj.isHidden;
}];
NSMutableArray *newArray = [[array objectsAtIndexes:indexes] mutableCopy];
However, doing the above does not work, I can't create a new array because it is being monitored by the UITableView, and I want to preserve the fine grained notifications that we get from the insertions and removals from the model array rather than reloading the entire table when a change occurs. So what I need is a way to only get notifications from newly inserted or removed items from the model that also meet the criteria.
So what, I think, I really want is two arrays, one that is the model, and another is the filtered presentation array. The presentation array will register for KVO notifications with the model array. The UITableView will register for notifications on the filtered presentation array. So if the insertion occurs in the model array it will send notification to the presentation array, then I need to check if it meets the criteria before inserting it in the presentation array or if it does not, then ignore the insertion. The problem I having is getting this to work correctly, the order of the items in the model is important and must be preserved. Any help or suggestions for alternative approaches would be greatly appreciated.
you have to maintain the model array and combinate the notification with the new array. So for example:
#property (nonatomic, strong) NSArray *modelArray;
//This array is also initialized obviously
#property (nonatomic, strong) NSArray *filteredArray;
//On this array you put the array filtered and connect this with the notification.
//So you can start each time from the model array and set the filtered array (and so
//change automatically the tableView).
is it possible to declare an NSArray withobjects of view controllers?
I'm trying to use two buttons to call an array that will loop through and count through 20 different views.
Right now, my array works in calling and displaying multiple images in a single view application.
what would i do to create an nsarray of view controllers, so that every time the "next" action method is called, a new view is loaded, and essentially, counted through the array?
This is currently what I have listed in my array
-(IBAction)getNextView {
imageArray=[[NSArray arrayWithObjects:
[firstViewController.view],
[secondViewController.view],
[thirdViewController.view];
}
But I think i am missing a valid point of updating the mainview with the elements in the array...
Thanks!
UPDATE :
This is what I am trying to achieve...
yes why not, you can create an NSArray with objects of viewControllers