How to display an NSArray in a UILabel and use timer

好久不见. 提交于 2019-12-12 04:44:21

问题


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];
} 

回答1:


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];
}



回答2:


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.



来源:https://stackoverflow.com/questions/8018688/how-to-display-an-nsarray-in-a-uilabel-and-use-timer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!