How to display an NSArray in a UILabel and use tim

2019-09-10 22:00发布

I'm trying to display an array of numbers in a UILabel using a timer,and show them in the order set in the array, but I only receive the Title in the format and then a SIGABRT ! any suggestions...Thanks

Part of the code with problems!

-(IBAction) rotate3
{
    NSString *number = [dayArray initWithArray:(NSArray *)dayArray];
    NSArray *array = [[NSArray alloc] initWithObjects: @"0", @"1", @"2", @"3", @"4", @"5" ,@"6", @"7", @"8",@"9",@"10",@"11",@"12",@"13", @"14", @"15", @"16", @"17", @"18", @"19",nil];
    numberCount++;
    timer=[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(rotate3 )userInfo:nil repeats:YES];    
    self.dayArray = array;
    [array release];

    label.text = [[NSString alloc] initWithFormat:@"Day %@  " number];
} 

2条回答
ゆ 、 Hurt°
2楼-- · 2019-09-10 22:52

Your SIGABRT is probably due to stack corruption: NSTimer can only be used with selectors of the form:

- (void)myTimerFireMethod: (NSTimer *)timer;

but you're trying to use it with

- (void)rotate3;

which doesn't take enough arguments.

查看更多
聊天终结者
3楼-- · 2019-09-10 22:54

It is very strange string : [dayArray initWithArray:(NSArray *)dayArray];. Try this:

-(IBAction) rotate3
{
    NSString *number = [self.dayArray description];
    NSArray *array = [[NSArray alloc] initWithObjects: @"0", @"1", @"2", @"3", @"4", @"5" ,@"6", @"7", @"8",@"9",@"10",@"11",@"12",@"13", @"14", @"15", @"16", @"17", @"18", @"19",nil];
    numberCount++;
    timer=[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(rotate3 )userInfo:nil repeats:YES];    
    self.dayArray = array;
    [array release];

    label.text = [NSString stringWithFormat:@"Day %@  ", number];
}
查看更多
登录 后发表回答