NSIndexPath* updatedPath = [NSIndexPath indexPathForRow: 0 inSection: 0];
NSIndexPath* updatedPath2 = [NSIndexPath indexPathForRow: 1 inSection: 0];
NSArray* updatedPaths = [NSArray arrayWithObjects:updatedPath, updatedPath2, nil];
[self.mySexyTableView reloadRowsAtIndexPaths:updatedPaths withRowAnimation:UITableViewRowAnimationTop];
Run Code Online (Sandbox Code Playgroud)
上面的代码工作,它动画.问题是我有很多数据,我不想硬编码行索引.由于我的表中只有一个部分可以为0.如何动态生成NSIndexPath对象的NSArray?
或者是否有更简单的方法来为表格视图设置动画.当用户单击表视图顶部的选项卡时,表视图中的所有行都会更改.
我有一个可能有数百个元素的NSArray.我想删除除了第一个元素之外的所有元素.想法?
我正在使用以下代码尝试将数组输出连接到NSString.
NSArray *array1 = [NSArray arrayWithObjects:[item objectForKey:@"id"], nil];
NSString *joinedString = [array1 componentsJoinedByString:@","];
NSLog(@"joinedString is %@", joinedString);
Run Code Online (Sandbox Code Playgroud)
我想这个输出连接的字符串为:join string是55,56,57,66,88 ......等...输出的时刻是:
2013-03-05 13:13:17.052 [63705:907] joinedString is 55
2013-03-05 13:13:17.056 [63705:907] joinedString is 56
2013-03-05 13:13:17.060 [63705:907] joinedString is 57
2013-03-05 13:13:17.064 [63705:907] joinedString is 66
Run Code Online (Sandbox Code Playgroud) 我有一个包含字符串的数组.其中一些字符串可能为空(@"").谓词必须如何看起来过滤数组并返回一个只包含非空字符串的新数组:
数组A:{"A","B","","D"} - >过滤器 - >数组B:{"A","B","D"}
它也应该返回:
数组A:{"","","",""} - >过滤器 - >数组B:{}
看起来这个[__NSArrayI allKeys]: unrecognized selector sent to instance错误,它似乎发生在你发送NSArray的allKeys消息时NSDictionary,但是在这种情况下我很清楚地将它发送到NSDictionary.
这是我与Pocket API接口时使用的代码:
NSDictionary *articles = [response objectForKey:@"list"];
// Create an array we can use to sort the keys (and thus the articles) in order of when they were added
NSMutableArray *allKeys = [[articles allKeys] mutableCopy];
Run Code Online (Sandbox Code Playgroud)
最后一行导致错误.但是articles非常明确地宣称是NSDictionary?为什么不喜欢它?
奇怪的是,如果我在运行时检查它,它说它是一个NSArray!为什么会改变?
(lldb) po articles
$5 = 0x082103e0 <__NSArrayI 0x82103e0>(
)
(lldb) po [articles class]
$6 = 0x01b83b8c __NSArrayI
(lldb)
Run Code Online (Sandbox Code Playgroud) 这是我的代码
NSMutableArray * reversedNamesArray; //theres about a thousand variable already stored in here, this is just for documentation
reversedNamesArray = [reversedNamesArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
//Incompatible pointer type assigning "NSMutableArray" to "NSArray"
Run Code Online (Sandbox Code Playgroud)
上面的消息是我得到的,我知道这意味着什么,但我不想采取额外的步骤将一千个变量的NSMutableArray复制到NSArray是否有任何演员我可以用来修复警告,它没有不会影响我的代码,但我只想修复它.你能解释为什么它们不兼容,它们NSMutableArray和NSArray应该使用相同数量的字节,所以我不明白为什么它们首先是不兼容的.
我在Objective C中有一个二维NSArray.
我想知道数组中的项目总数.如果不使用嵌套的for循环,是否有更快的方法来获取项目的总数?
谢谢!
先生问题是------我从url获取数据和arrayobj中的数据.当我运行这个项目时,我收到了这个错误.我做错了声明或项目中的代码请检查connectiondidfinishloading和cellforrowanindexpath.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error ;
NSMutableDictionary *dictobj = [NSJSONSerialization JSONObjectWithData:dataobj options:NSJSONReadingMutableContainers error:&error];
newsobj=[dictobj objectForKey:@"news"];
//NSArray *longdeceobj=[newsobj objectForKey:@"long_desc"];
for (NSDictionary *dict in newsobj)
{
NSDictionary *title=[dict objectForKey:@"title"];
[arrayobj addObject:title];
}
[[self tableobj]reloadData];
}
Run Code Online (Sandbox Code Playgroud)
//这是索引路径代码中行的单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString*cellide=@"identifier";
newcustomobj=(newsCustamView *) [tableView dequeueReusableCellWithIdentifier:cellide];
if (newcustomobj==nil)
{
[[NSBundle mainBundle]loadNibNamed:@"newsCustamView" owner:self options:nil];
}
newcustomobj.newstitle.text=[[[arrayobj objectAtIndex:0]objectForKey:@"news"]objectForKey:@"title"];
return newcustomobj;
}
Run Code Online (Sandbox Code Playgroud)
错误是:
2014-05-23 18:34:04.913 newsdata[6518:90b] -[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x9c515c0
2014-05-23 18:34:04.915 …Run Code Online (Sandbox Code Playgroud) 我知道你可以做一些像[..."SELF.some_id == [c]%d AND SELF.some_id == [c]%d",id1,id2],但我还需要更多.有没有办法在不构建字符串的情况下执行此操作.
例如...
NSArray *arrayOfWantedWidgetIds = @[1,3,5,6,9,13,14,16];
NSMutableArray *allWidgets = [[WidgetManager sharedWidget] getAllWidgets];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.widget_id ==[c] %d", arrayOfWantedWidgetIds]; //obviously we can't do this, it won't accept an array of IDS for %d
[allWidgets filterArrayUsingPredicate:predicate];
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现这样的目标?另一种方式......如果我循环这个,并为arrayOfWantedWidgetIds中的每个值创建单独的谓词,然后将所有单个谓词添加到数组中......这也无济于事,因为filterArrayUsingPredicate只接受NSPredicate.不是他们的数组.
我正在尝试更改数组中字典的值.我在PlayGround中制作了一个小型原型:
var arr = [NSDictionary]()
arr.append(["name":"blue","view":"<object id=\"6787\">","visible":"true","locked":"false"])
arr.append(["name":"yellow","view":"<object id=\"345\">","visible":"true","locked":"false"])
arr.append(["name":"green","view":"<object id=\"123\">","visible":"false","locked":"true"])
//test remove
arr.removeAtIndex(2)
arr.count
//test edit
let nameChange = arr[1]
nameChange.setValue("black", forKey: "name")
arr[1]
Run Code Online (Sandbox Code Playgroud)
有人能帮帮我吗?
nsarray ×10
objective-c ×9
ios ×5
iphone ×2
nsdictionary ×2
nspredicate ×2
api ×1
arrays ×1
cocoa ×1
swift ×1
swift2 ×1
uitableview ×1
view ×1