标签: nsarray

UITableView从NSMutableArray/NSDictionary循环输出数据

我目前正在构建一个iPhone应用程序,它将显示来自名为"故事"的NSMutableArray的数据.数组结构如此(通过NSLog):

    2009-07-20 12:38:30.541 testapp[4797:20b] (
    {
    link = "http://www.testing.com";
    message = "testing";
    username = "test";
},
    {
    link = "http://www.testing2.com";
    message = "testing2";
    username = "test2";
} )
Run Code Online (Sandbox Code Playgroud)

我的cellForRowAtIndexPath目前看起来像这样:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];


}

    for (NSDictionary *story in stories) {
        [cell setTextColor:[UIColor whiteColor]];
        [cell setFont: [UIFont systemFontOfSize:11]];
        cell.text = [NSString stringWithFormat:[story objectForKey:@"message"]];
    }
            return cell; …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch objective-c uitableview nsarray

0
推荐指数
1
解决办法
9098
查看次数

目标C提示?

我想替换这个:

self.fajerImage     = [UIImage imageNamed:@"FirstViewBG_5N.png"];
self.shrogImage     = [UIImage imageNamed:@"FirstViewBG_4N.png"];
self.dohorImage     = [UIImage imageNamed:@"FirstViewBG_3N.png"];
self.aaserImage     = [UIImage imageNamed:@"FirstViewBG_2N.png"];
self.mgribImage     = [UIImage imageNamed:@"FirstViewBG_1N.png"];
self.eeshaImage     = [UIImage imageNamed:@"FirstViewBG_0N.png"];
Run Code Online (Sandbox Code Playgroud)

有一个for循环..我不知道如何在循环中一个接一个地调用ivars ..

请注意,在循环之前将它们放在一个数组中是个好主意,我没有成功实现..

谢谢!

setter for-loop objective-c instance-variables nsarray

0
推荐指数
1
解决办法
170
查看次数

为什么在NSArray InitWithObjects期间此代码会因EXC_BAD_ACCESS而崩溃

请注意下面的代码中的两个NSLOG语句.打印出"aaa",但"bbb"从未打印过.相反,模拟器与EXC_BAD_ACCESS崩溃.我知道这通常意味着我试图访问的对象过早地被释放.我只是想不通有什么问题......

更新:

这是我的.h

#import <UIKit/UIKit.h>


@interface vcAddCat : UIViewController  <UIPickerViewDataSource, UIPickerViewDelegate> {

NSManagedObjectContext *managedObjectContext;

IBOutlet UIPickerView * pickerView;
NSArray * _weights;
NSArray * _categories;
IBOutlet UILabel *lastCat;
IBOutlet UILabel *lastWeight;
Run Code Online (Sandbox Code Playgroud)

}

我没有任何数组的@property或@synthesize行...

这是我的.m的两个剪辑

- (void)viewDidLoad {

    [super viewDidLoad];
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);

    _categories=[[NSArray alloc] initWithObjects: @"Homework",@"Quizzes",@"Tests", @"Mid-Term Exam", nil];
;

    NSLog(@"aaa");

    _weights=[[NSArray alloc] initWithObjects: @"1",@"2",@"3",@"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"11", @"12", @"13", @"14", @"15", @"16", @"17", @"18", @"19", @"20", @"21",@"22",@"23", @"24", @"25", nil];


    NSLog(@"bbb");
Run Code Online (Sandbox Code Playgroud)

..这里是我发布阵列的地方......

- …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uitableview nsarray

0
推荐指数
1
解决办法
1536
查看次数

为什么我的排序结果会以完全随机的方式返回?

我的数组jokesarray有以下元素.我试图按嵌套元素"sec"排序.

每次我运行这个,我得到一个不同的排序顺序或每次我回到相同的视图(我的排序代码在viewwillappear).为什么?

    {
       "4eb57e72c7e24c014f000000" : {
         "_id" : {
           "$id" : "4eb57e72c7e24c014f000000"
         },
         "author" : "tim",
         "comments" : [],
         "created": {
           "sec" : 1320517234,
           "used" : 856000
         },
         "picture" : "http://someurl.com",
         "text" : "this is a test",
         "title" : "test",
         "type" : ["test"]
       }

    jokesArray = [unSortedContentArray sortedArrayUsingFunction:Sort_Created_Comparer context:self]; 

    NSInteger Sort_Created_Comparer(id array1, id array2, void *context)
{

    int v1 = (int)[[array1 objectForKey:@"created"] objectForKey:@"sec"];
    int v2 = (int)[[array2 objectForKey:@"created"] objectForKey:@"sec"];
    if (v1 < v2)
        return NSOrderedAscending;
    else if (v1 > v2) …
Run Code Online (Sandbox Code Playgroud)

objective-c nsarray ios

0
推荐指数
1
解决办法
75
查看次数

NSArray反向索引排序

这是我的 NSArray

myArray = [NSArray arrayWithObjects: @"a", @"b", @"c", @"d", @"e", nil];
Run Code Online (Sandbox Code Playgroud)

现在我像这样循环遍历数组:

int size = [myArray count];
NSLog(@"there are %d objects in the myArray", size);

for(int i = 1; i <= size; i++) {
    NSString * buttonTitle = [myArray objectAtIndex:i]; 
    // This gives me the order a, b, c, d, e 
    // but I'm looking to sort the array to get this order
    // e,d,c,b,a

    // Other operation use the i int value so i-- doesn't fit my needs …
Run Code Online (Sandbox Code Playgroud)

sorting objective-c nsarray ios

0
推荐指数
1
解决办法
1416
查看次数

在Objective-C中声明没有确定大小的数组

我需要一个在初始声明中不包含任何内容的字符串数组,因为我将把它用作我将从用户那里获得的字符串存储.我将通过循环来做到这一点.有人知道如何使用NSArray声明一个没有确定大小的数组吗?谢谢!

objective-c nsarray ios

0
推荐指数
1
解决办法
794
查看次数

B类NSArray返回NIL?

我只是试图在这两个类之间传递一个NSArray,每当我在B类中NSLog它的值时它返回NIL.

为什么这样,我如何让它显示到这个UITableView?

这是Class Ah

#import <UIKit/UIKit.h>
#import "Class B.h"

@class Class B;

@interface Class A : UIViewController  <UITableViewDataSource, UITableViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate, UIPopoverControllerDelegate> {

    IBOutlet UITableView *ToolsTable;
    IBOutlet UICollectionView *strategyCollection;
    IBOutlet UIButton *countButton;
    IBOutlet UIButton *camerButton;
    IBOutlet UIButton *videoButton;
    IBOutlet UIButton *textButton;
    IBOutlet UIButton *probeButton;
    IBOutlet STPopOverQuestionViewViewController *questionListController;
    IBOutlet UIPopoverController *questionList;
    NSMutableDictionary *stratToolsDict;
    NSMutableArray *stratTools;
    NSMutableArray *stratObjects;
    NSMutableDictionary *QuestionDict;
    NSMutableArray *QuestionsList;
}

@property (strong, nonatomic) IBOutlet UIView *strategyOBJView;
@property (retain, nonatomic) NSMutableDictionary *stratToolsDict;
@property (retain, nonatomic) NSMutableArray *stratTools;
@property (retain, nonatomic) …
Run Code Online (Sandbox Code Playgroud)

nsmutablearray nsarray ipad

0
推荐指数
1
解决办法
64
查看次数

如何在NSArray中更改对象

我有两个NSArrays,我想在第一个中更改一个对象,NSArray在第二个中更改另一个对象NSArray.

这是我试图做的,但没有运气:

[[arrrndwords objectsinindex:i] replace object in index:1 with:[arrword indexinobject:rndnum]];
Run Code Online (Sandbox Code Playgroud)

当我运行它时,它会让我退出应用程序.

objective-c nsarray

0
推荐指数
1
解决办法
1万
查看次数

对于tableview部分,按日期对NSArray组进行分组

我有以下NSArray,我希望将所有包含相同日期的对象分组.我想对这些对象进行分组,然后在TableView中显示它们,该组中的对象在TableView的各自部分中具有相同的日期.在每个部分中,我希望事件按照事件从最早到最晚的时间开始的时间列出.

检索的数据来自Parse数据库.(不确定这是否重要).

下面是阵列结果

DATA (

"<Sessions:QtJKSToEu9:(null)> {\n    date = \"2013-11-19 18:30:00 +0000\";\n    description = \"Seating assignment on name badge.\";\n    location = \"Center Stage\";\n    name = \"Dinner and CARE Awards Celebration\";\n}",

"<Sessions:btZ5eRZffl:(null)> {\n    date = \"2013-11-19 20:30:00 +0000\";\n    description = \"Brief meeting\";\n    location = \"Cedar Room\";\n    name = \"Store Manager Advisory Board Members\";\n}",

"<Sessions:HY4VtgBncd:(null)> {\n    date = \"2013-11-20 07:00:00 +0000\";\n    description = Breakfast;\n    location = Ballrooms;\n    name = Breakfast;\n}",

"<Sessions:6p6t2uL5Jf:(null)> {\n    date = \"2013-11-20 11:30:00 +0000\";\n    description = Lunch;\n    location = …
Run Code Online (Sandbox Code Playgroud)

nsarray ios

0
推荐指数
1
解决办法
1903
查看次数

创建一个格式数组array [] [@"string"];

我正在尝试创建一个类似于这样创建的数组:

NSData *jsonData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"www.example.com/j.php"]];
NSError *error = nil;
if (jsonData) {
     result = [NSJSONSerialization JSONObjectWithData:jsonData
                                              options:NSJSONReadingMutableContainers 
                                                error:&error];
}
Run Code Online (Sandbox Code Playgroud)

这里www.example.com/j.php是JSON,看起来像这样:

[{"name":"matt","genre":"Photography","info":"foo","date":"2014-06-12"},{"name":"jamie","genre":"Art","info":"Bar","date":"2014-06-13"}]
Run Code Online (Sandbox Code Playgroud)

然后使用这个数组

result[indexPath.row][@"name"];
Run Code Online (Sandbox Code Playgroud)

如何使用我自己的名称,流派和信息构建一个新的NSArray,其格式与上面的相同?


我试图使用日志打印数组,但它出现了 (null)

我知道我不是这样创建的:

[NSArray arrayWithObjects: @"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", nil]
Run Code Online (Sandbox Code Playgroud)

arrays objective-c nsarray ios

0
推荐指数
1
解决办法
80
查看次数