- (void)webViewDidFinishLoad:(UIWebView *)webView {
if (urlIndex == maxIndex) {
maxIndex = maxIndex + 1;
NSString* sURL = webpage.request.URL.absoluteString;
[urlHistory addObject:sURL];
NSLog(@"%d: %@", urlIndex, [urlHistory objectAtIndex:urlIndex]);
NSLog(@"%d: %@", urlIndex, webpage.request.URL.absoluteString);
[sURL release];
urlIndex = urlIndex + 1;
}
else {
[urlHistory insertObject:webView.request.URL.absoluteString atIndex:(urlIndex - 1)];
}
}
Run Code Online (Sandbox Code Playgroud)
这条线
NSLog(@"%d: %@", urlIndex, [urlHistory objectAtIndex:urlIndex]);
Run Code Online (Sandbox Code Playgroud)
print(null),同时作为这一行
NSLog(@"%d: %@", urlIndex, webpage.request.URL.absoluteString);
Run Code Online (Sandbox Code Playgroud)
打印实际的URL.
在我的initWithNibName上,我有:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:@"Tab1ViewController" bundle:nil];
if (self) {
urlHistory = [[NSMutableArray alloc] init];
urlIndex = …Run Code Online (Sandbox Code Playgroud) 我有一个数组,其中包含一些可能相同但有些不同的对象.
如何分别取出每个相同的对象和不同的对象?
下面是数组
NSMutableArray *items = [[NSMutableArray alloc]
initWithArray:[NSArray arrayWithObjects:@"rat", @"rat", @"cat",@"Lion", @"cat", @"dog", @"dog", nil]];
Run Code Online (Sandbox Code Playgroud)
我想要有四个包含这些项目的数组:
将物体拿出来的最佳方法是什么?相同的对象应放在同一个数组中.
@property(nonatomic,strong)NSMutableArray*authorMutableArray;
- (id)init {
self = [super init];
if (self) {
self.authorMutableArray = [[NSMutableArray alloc] initWithObjects:@"First Row", @"Second Row", nil];
for (NSString *string in authorMutableArray) {
NSLog(@"String: %@", string);
}
NSLog(@"Init in Add Model with Author count:%i", [authorMutableArray count]);
}
}
Run Code Online (Sandbox Code Playgroud)
访问该属性的示例.NSLog始终将计数显示为0.
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
if (indexPath.row == [self.addModel.authorMutableArray count] - 1 ) {
NSLog(@"count of %i", [self.addModel.authorMutableArray count]);
return UITableViewCellEditingStyleInsert;
}
else {
return UITableViewCellEditingStyleDelete;
}
}
else {
return UITableViewCellEditingStyleNone; …Run Code Online (Sandbox Code Playgroud) NSMutableArray *tmpMutArr = [NSMutableArray arrayWithArray:allObjectsArray];
NSLog(@"The content of array is%@",tmpMutArr);
int index;
for (int i=0;i<[tmpMutArr count];i++)
{
if([[tmpMutArr objectAtIndex:i] isKindOfClass:[NSDictionary class]])
{
NSMutableDictionary *tempDict = [tmpMutArr objectAtIndex:i];
if([[tempDict valueForKey:@"Name"] isEqualToString:[NSString stringWithFormat:@"%@", nameString]])
{
index = i;
}
}
}
[tmpMutArr replaceObjectAtIndex:index withObject:[NSDictionary dictionaryWithDictionary:mutDict]];
Run Code Online (Sandbox Code Playgroud)
此代码不会像我想要的那样替换tmpMutArr中的匹配对象,而是替换tmpMutArr中的所有对象.如何只替换我想要的索引?
我知道tmpMutArr在替换之前包含所有对象,所以我只需要正确指定索引.怎么办?
我正在尝试构建一个示例应用程序,它从URL中抓取一些json并将其显示在表视图中.我在将数据存储到对象中并将这些对象插入NSMutableArray时遇到问题.
TableView.m
- (void) getDataFromAPI {
NSString *endpoint = @"http://www.somesite.com/list.php";
NSURL *url = [NSURL URLWithString:endpoint];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
[self createMovies: JSON];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response , NSError *error , id JSON){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Uh oh, there's been a problem!" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Retry", nil];
[alert show];
}];
[operation start];
}
- (void) createMovies: (id) json {
NSMutableArray *list = [[NSMutableArray alloc] init]; …Run Code Online (Sandbox Code Playgroud) 我有NSArray一些像以下格式的东西.
组数组是:
(
"Q-1-A1",
"Q-1-A9",
"Q-2-A1",
"Q-2-A5",
"Q-3-A1",
"Q-3-A8",
"Q-4-A1",
"Q-4-A4",
"Q-10-A2",
"Q-8-A2",
"Q-9-A2",
"Q-7-A1",
"Q-5-A2"
)
Run Code Online (Sandbox Code Playgroud)
现在我要做的是将数组元素分组这样的东西.
1 = ( "Q-1-A1","Q-1-A9")
2 = ("Q-2-A1","Q-2-A5",) ...
10 =("Q-10-A2")
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我如何实现这一目标.
提前致谢.
如何根据图像的高度对NSMutableArray图像进行排序?我是否需要找到每个图像的高度并按顺序添加它,还是有更简单的方法?
我试图从我的数组中删除一些东西,但我得到了异常
删除时无法识别的选择器
我的代码:
NSMutableArray* tempNewsArray = [[NSMutableArray alloc]init];
tempNewsArray = [[defaults objectForKey:@"NewsArray"]mutableCopy];
for(int i = 0;i< [tempNewsArray count]-1;i++)
{
if( (monthIntofNew - month <= 10 && monthIntofNew - month !=0) || ( monthIntofNew - month <= -2))
{
[tempNewsArray delete:[tempNewsArray objectAtIndex:i]];//exception occurs here.
//deleted
}
}
Run Code Online (Sandbox Code Playgroud)
我想我错过了什么,请帮忙吗?
有两个可变数组,根据一些语句控制流程将对象添加到不同的可变数组中.我知道我可以使用,[theMutableArray addObject: anyObject]但我认为有点冗长.我真正需要的是[object addTo: (statement ? theMutableArrayA : theMutableArrayB)].
那么,有没有addObject被动方法?
我有一个NSMutableArray像这样的
(
{
Realimg = "<UIImage: 0x13951b130>, {800, 600}";
"bid_accepted" = 1;
"bid_amount" = 100;
"bid_amount_num" = 100;
"bid_cur_name" = USD;
"bid_cur_symb" = $;
"bid_currencycode" = 4;
"bid_date" = "05 Nov 2015";
"bid_msg" = testing;
"bid_user_id" = 2;
"nego_id" = 612;
"pas_count" = 5;
"ride_address" = "Sample Address";
"ride_cover_img" = "uploadfiles/UploadUserImages/2/mobile/21426739600s-end-horton-plains.jpg";
"ride_id" = 149;
"ride_name" = "Ride to the World's End";
"ride_type_id" = 0;
"ride_type_name" = Travel;
"ride_user_fname" = Nik;
"ride_user_id" = 2;
"ride_user_lname" = Mike;
}
) …Run Code Online (Sandbox Code Playgroud) nsmutablearray ×10
ios ×9
objective-c ×7
cocoa ×1
indexing ×1
iphone ×1
nsdictionary ×1
nsstring ×1
uiimage ×1
xcode ×1