nsmutablearray

Can I shift the objects in a NSMutableArray without creating a temporary array?

爱⌒轻易说出口 提交于 2019-12-23 08:56:31
问题 I thought I had it with, void shiftArray(NSMutableArray *mutableArray, NSUInteger shift) { for (NSUInteger i = 0; i < [mutableArray count]; i++) { NSUInteger newIndex = (i + shift) % [mutableArray count]; [mutableArray exchangeObjectAtIndex:i withObjectAtIndex:newIndex]; } } which turns 0,1,2,3,4 into 0,2,3,4,1 when I shift by one. The expected result is 4,0,1,2,3 I feel like I'm missing something obvious... Update: Thanks Matthieu, this is what my function looks like now. void

Group elements of array on another array

放肆的年华 提交于 2019-12-23 05:43:08
问题 I have an array of object and each object have a date. I want to group on another array each object with the same date. My idea is this: sort the array by date of objects, for each object on array do this: if object at index i has the same date of object at index i + 1, add the object at index i to a temporary array; else add object at index i to a temporary array, add the array to my output array and remove all objects from my temporary array. My code is this: - (void) group{ NSMutableArray

Pass NSMutableArray between two UIViewController's

被刻印的时光 ゝ 提交于 2019-12-23 05:15:26
问题 I have two view controllers name RootViewController and SecondViewController. In the FirstViewController I have this NSMutableArray @interface RootViewController : UITableViewController { NSMutableArray *allClasses;}@property (nonatomic,retain) NSMutableArray *allClasses; In the RootViewController I populate the UITableView with all the objects within allClasses In my SecondViewController I have @interface SecondViewController : UIViewController <UITextFieldDelegate,UIPickerViewDelegate> {

Store users contacts in NSMutable array after access is granted for address book

我只是一个虾纸丫 提交于 2019-12-23 04:45:53
问题 I'm using this in my viewWillAppear: to ask the user for permission/access(as apple requires) to their address book. When they have allowed access, they can proceed to an "invites" page, where they can browse through (their own)contacts that already have existing accounts on my app . Basically, I'm just going to take their contacts and put it into a UITableView . SO, I MUST GET ALL THEIR CONTACTS AND ADD IT TO AN array of type NSMutableArray . In the following code, where it says "//ADD ALL

Sum duplicate on NSMutableArray

随声附和 提交于 2019-12-23 03:32:08
问题 I have a NSMutableArray with objects of type NSMutableDictionary , the NSMutableDictionary contains 2 keys -Airlines (string) -Rating (integer) I have an NSMutableArray with all the objects and what i need is to Sum the rating of all the airline companies repeated objects, an example: Airline Rating A 2 B 3 B 4 C 5 The end result array will be the A = 2, C = 5 and the Sum of B´s that is equal to 7. My code so far: for (int i = 0; i < arrayMealRating.count; ++i) { NSMutableDictionary *item =

Need to access detailTextLabel property of UITableViewCell when button is pressed

ぃ、小莉子 提交于 2019-12-23 02:10:07
问题 I have programmatically created a UITableView and I have also programmatically created UIButtons to be included with every cell / row. I have set these buttons so that if they are tapped, their button image changes. So when the user first sees the table view, the buttons are the color grey, but if the user taps one of the buttons, then that button will turn red. If they tap it again, it will turn back to grey. I need to make it so that if a button has been pressed, and is currently using the

Implementing Custom NSMutableArray

落花浮王杯 提交于 2019-12-22 18:38:09
问题 I would like to create my own custom NSMutableArray of my custom objects: @interface Course : NSObject { NSString *className; NSString *classGrade; NSInteger creditHours; } This class will store an array of courses : @interface AllCourses : NSObject : NSMutableArray{ NSMutableArray *arrClasses; } I would like "AllCourses" to inherit from NSMutableArray so i can use it like any other NSMutableArray Object and add\remove courses from it and load it into a tableView etc... So my question is ,if

IOS实现多媒体音频之音乐播放器

Deadly 提交于 2019-12-22 13:59:14
  随着智能手机市场越来越活跃,相应的app也变得五彩缤纷,各式各样,让你的app更吸引人多媒体技术不可避免。通过对音频和视频等控制让你的app更加丰富多彩,今天和大家一起研究下基本的音频使用。本文只提供部分代码,如果疑问可以 下载源码 查看。   功能主界面如下: 首先引入音频播放框架    2、通过故事版搭建界面,由于该步骤很简单,这里不讲解。如图所示: 3、定义变量存放数据,并将文件中歌曲信息封装成模型放入数组 /** 加载歌曲数据*/ @property(nonatomic,strong) NSMutableArray * dataArray; /** 保存cell数据控制颜色*/ @property(nonatomic,strong) NSMutableArray * cellArray; /** 当前正在播放的音乐*/ @property(nonatomic,strong) JRPlayerViewController * playerVC; /** 上次播放的音乐*/ @property(nonatomic,strong) NSIndexPath * front; #pragma mark - 加载数据 - (void) _loadData{ NSString * path=[[NSBundle mainBundle] pathForResource:@"Musics

NSPredicate Sort Array and Order DESC

拜拜、爱过 提交于 2019-12-22 13:55:11
问题 I have an NSMutableArray containing TBPosts that I would like to filter in descending order according to the commentsCount and likesCount of the TBPost . Initially, the first object in the filtered array will be the object with the largest number of comments and likes, which can be worked out by adding the two together. So I tried the following query and receive an Unable to Parse error. Please can you tell me where I am going wrong? [posts filterUsingPredicate:[NSPredicate

How to lazy load?

无人久伴 提交于 2019-12-22 11:28:24
问题 How do you lazy load a NSMutableArray in tableView:didSelectRowAtIndexPath: ? I am very new to Objective-C, XCode, and iOS programming, so any help is appreciated. 回答1: Lazy load means 'loading on demand'. So you perform operation only when it is really necessary, and not beforehand. Say we have method: -(void) init { self = [super init]; mMyMemberArray = [self loadSomeDataToArray]; } -(void) tableView:didSelectRowAtIndexPath: { [someObject processData: mMyMemberArray]; } This is not lazy