如果有人NSString
需要一个用户 ID 用作请求的 URL:
有一个NSMutableArray
他想一次一个地加入上述呼叫?所以基本上NSString
从NSMutableArray
.
可以检查多个 UITableView 单元格,一旦完成,我可以索引哪些单元格行被推送。这就是现在使用的 userIDArray 我想用从 userIDArray 返回的用户 ID 进行呼叫。
for (NSDictionary* userIDDict in userIDArray)
{
userIDArray = [[NSMutableArray alloc] init]; //I put this line in my viewdidload
NSNumber* userID = [userIDDict objectForKey:@"UserID"];
}
UserIDArray 是NSMutableArray
.
这将是NSLog
来自NSMutableArray
The Integer 的 1、2 和 3。
UserID: 1
UserID: 2
UserID: 3
因此,换句话说,我想将NSMultiTableArray
1,2 和 3 的结果用于NSString
:
NSString *userProfile = [NSString stringWithFormat:@"http://example.com/userid=1"];
NSString *userProfile = [NSString stringWithFormat:@"http://example.com/userid=2"];
NSString *userProfile = [NSString stringWithFormat:@"http://example.com/userid=3"];
所以我会打第一个电话并等待结果,然后是第二个,最后是第三个。
这可以做到吗?我已经搜索了这个关于队列和这个的链接,但我不确定这些是否是我需要的?
UserDetailViewController.h 文件:
@interface UserDetailViewController : UIViewController <UITableViewDelegate>{
long long expectedLength;
long long currentLength;
UITableView *userTableView;
NSIndexPath* checkedIndexPath;
}
@property (nonatomic, retain) NSArray *userIDJson;
@property (strong, nonatomic) NSDictionary *userIDDict;
@property (nonatomic, retain) NSIndexPath* checkedIndexPath;
@property (nonatomic, strong) NSMutableArray *userIDArray;
@property (nonatomic) NSInteger currentUserIndex;
@end
UserDetailViewController.m 文件:
@interface UserDetailViewController ()
@end
@implementation UserDetailViewController
@synthesize userIDJson;
@synthesize userIDDict;
@synthesize checkedIndexPath;
@synthesize userIDArray;
@synthesize currentUserIndex;
- (void)viewDidLoad
{
[super viewDidLoad];
userIDArray = [[NSMutableArray alloc] init];
[self.navigationController setNavigationBarHidden:NO];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//return self.loadedSearches.count;
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.userIDJson.count;
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;
}
cell.textLabel.text = self.userIDJson[indexPath.row][@"UserName"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if([self.checkedIndexPath isEqual:indexPath])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
NSString *userStringIndex = [self.userIDJson objectAtIndex:indexPath.row];
if (thisCell.accessoryType == UITableViewCellAccessoryNone)
{
thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
[userIDArray addObject:userStringIndex];
}
else
{
thisCell.accessoryType = UITableViewCellAccessoryNone;
[userIDArray removeObject:userStringIndex];
}
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
if (self.currentUserIndex < userIDArray.count) {
NSNumber* userID = [[userIDArray objectForIndex:currentUserIndex]objectForKey:@"UserID"];
//Make the actual request here, and assign the delegate.
NSString *userProfile = [NSString stringWithFormat:@"http://example.com/userid=%@",userID];
self.currentUserIndex++;
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:userProfile]];
NSString *userResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
NSURL *url = [[NSURL alloc] initWithString: userProfile];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
userIDJson = [NSJSONSerialization JSONObjectWithData:dataURL
options:kNilOptions
error:&error];
}
}
for (userIDDict in userIDArray)
{
NSNumber* userID = [userIDDict objectForKey:@"UserID"];
NSLog(@"%@", userID);
NSArray* userName = [userIDDict objectForKey:@"UserName"];
}