小编Ven*_*enk的帖子

UILabel在重新加载时不会在UITableViewCell中刷新

我将两个添加UILabels到a UITableViewCell,然后为该单元格命名和编号标签.当我重新加载数据时UITableView(无论是从表格视图添加还是删除联系人),标签中的数据都是重叠的,这意味着它不会重新加载标签,直到重新加载整个视图.

有人可以帮忙吗?

码:

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

    static NSString *CellIdentifier = @"Cell";
    UILabel *name;
    UILabel *number;

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

        //NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
        //      NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
        //      [sortDescriptor release];
    }
    CGRect Label1Frame = CGRectMake(10, 10, 140, 25);
    name = [[UILabel alloc] initWithFrame:Label1Frame];
    name.tag = 1;
    [name setBackgroundColor:[UIColor clearColor]];
    [cell.contentView addSubview:name];

    CGRect …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uitableview uilabel ios

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

drawRect在UIView子类上调用,但不在UIViewController上调用

到目前为止,我的代码工作正常,但我必须创建一个类UIView.这有点不方便,因为我也需要与ViewController进行交互.

顺便说一句,我曾尝试[self setNeedsDisplay]ViewDidLoad该的UIViewController子类的文件,但没有奏效.

这是代码,它在UIViewSubclass上工作但不会在一个上调用UIViewController:

- (void)drawRect:(CGRect)rect
{
    UIColor *currentColor = [UIColor redColor];

    CGContextRef context = UIGraphicsGetCurrentContext();

    someNum = 1;
    CGContextBeginPath(context);
    CGContextMoveToPoint(context, 30, 40);
    [self addDotImageX:30 andY:40];

    CGContextSetLineWidth(context, 2);
    CGContextSetStrokeColorWithColor(context, currentColor.CGColor);
    CGContextStrokePath(context);
}
Run Code Online (Sandbox Code Playgroud)

关于尝试什么的任何想法?顺便说一句,这是一个TabBar应用程序.我知道那些可以以某种方式阻止调用drawRect.

以编程方式创建的选项卡,而不是通过Nib.例如:

NSMutableArray *listOfViewControllers = [[NSMutableArray alloc] init];
UIViewController *vc;

vc = [[Education alloc] init];
vc.title = @"Education";
[listOfViewControllers addObject:vc];
vc.tabBarItem.image = [UIImage imageNamed:@"info.png"];
[vc release];
Run Code Online (Sandbox Code Playgroud)

我很感激任何想法.我已经浏览了这个网站上setNeedsDisplay没有打电话drawRect的答案,但没有找到我的具体案例的答案.

谢谢.

cocoa-touch objective-c uiviewcontroller uiview ios

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

indexOfObject第一次返回0而不是NSNotFound

我在a中有一个表UIPopoverController,viewDidAppear我检查了存储在standardUserDefaults中的单元格标签的值.(所以我可以使用最后选择的选项).

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *lastMenu = [prefs objectForKey:@"location"];

NSUInteger index = [__menuTitles indexOfObject:lastMenu];

NSLog(@"lastMenu is %@",lastMenu);
NSLog(@"lastMenu index is %i",index);
Run Code Online (Sandbox Code Playgroud)

在第一次激活菜单时生成此选项

lastMenu is 
lastMenu index is 0
Run Code Online (Sandbox Code Playgroud)

后续点击正确报告2147483647的含义 NSNotFound

lastMenu is 
lastMenu index is 2147483647
Run Code Online (Sandbox Code Playgroud)

为什么0第一次返回?

这是阵列

__menuTitles = [[NSArray alloc] initWithObjects:
                @"North America", 
                @"Western Europe", 
                @"Asia Pacific", 
                @"Latin America", 
                @"Central & Eastern Europe", 
                @"Middle East", 
                @"Africa", 
                nil];
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsarray ios

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

UIImageView alloc] initWithImage使用IBOutlet无法正常工作

我通常遵循在我的方法中创建一个对象的模式(比如viewDidLoad),让属性保持在它上面,然后释放创建的原始对象.所以像这样:

NSArray *myArray = [NSArray alloc] initWithObjects:@"1", @"2", @"3", nil];
self.array = myArray;
[myArray release];
Run Code Online (Sandbox Code Playgroud)

我以为我可以做同样的事情UIImageView.我有一个UIImageView创建我的.xib.我有一个出口,这是一个像这样的财产

@property (nonatomic, retain) IBOutlet UIImageView *imageView;
Run Code Online (Sandbox Code Playgroud)

在我viewDidLoad,我做:

UIImageView *imgView = [[UIImageView alloc] initWithImage;[UIImage imageNamed:@"arrow.png"]];
self.imageView = imgView;
[imgView release];
Run Code Online (Sandbox Code Playgroud)

如果我运行它,我在屏幕上没有任何东西.但是,如果我在我这样做viewDidLoad:

[self.imageView setImage:[UIImage imageNamed:@"arrow.png"]];
Run Code Online (Sandbox Code Playgroud)

我确实在屏幕上显示了我的箭头图像.是否有关于不同的东西UIImageView,我很想念这里?

由于第一次响应而编辑:UIImageView不同于UITableView我需要将其作为子视图添加到当前视图中吗?当我创建一个UITableViewin时IB,我不会将其添加为subviewin viewDidLoad.

谢谢.

iphone uiimageview

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

touchesMoved工作不够快

我想当用户从左到右标签计数器从1到5更新时.如果我慢慢地滑动,非常缓慢地工作,然后更快,它不能正常工作?还有其他方法可以实现吗?

我有这个代码:

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    gestureStartPoint = [touch locationInView:self.view];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];
    CGPoint currentPosition = [touch locationInView:self.view];

    if ((int)(currentPosition.x)%40 == 0 && counter < 5) {
        counter++;
    }

    [label setText:[NSString stringWithFormat:@"%d", counter]];

}
Run Code Online (Sandbox Code Playgroud)

iphone counter slide touchesmoved ios

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

自动引用计数不会释放calloc

in my application, for encoding the string i am using当我在配置文件中运行应用程序时,我正在使用ARC calloc`它在calloc中显示内存泄漏.

在此输入图像描述

是否ARC会释放calloc

如果不是,为什么它不释放以及如何释放calloc

谢谢,

iphone objective-c ipad ios automatic-ref-counting

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

如何在iOS中对已签名的数字进行排序?

这可能是一个简单的问题,但我不知道对有符号整数值数组进行排序的方法.

我的数组在排序之前,

pointsAry (-2,-7,-5,0,-3,2,-1,-4,1,3,-6)
Run Code Online (Sandbox Code Playgroud)

使用后

NSArray * sortedArray = [pointsAry sortedArrayUsingComparator:^(id str1, id str2){
        return [(NSString *)str1 compare:(NSString *)str2 options:NSNumericSearch];
    }];
Run Code Online (Sandbox Code Playgroud)

结果

sortedArray : (-1,-2,-3,-4,-5,-6,-7,0,1,2,3)
Run Code Online (Sandbox Code Playgroud)

对于有符号值,sortedArray格式不正确,所以我需要

(-7,-6,-5,-4,-3,-2,-1,0,1,2,3)
Run Code Online (Sandbox Code Playgroud)

如何按上述格式排序?提前致谢.

sorting iphone objective-c nsarray ios

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

无法设置UIImageView图像

我正在使用if语句UIImageView根据变量的值设置图像.这是声明:

- (void)configureView
{    
    if (self.detailItem) {
        if ([detailItem isEqualToNumber:[NSNumber numberWithInt:0]]) {
            [mapImageView setImage:[UIImage imageNamed:@"0.jpg"]];
            NSLog(@"derp");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

"derp"被打印但是UIImageView图像不会改变......如果我把setImage:声明放进去就行了viewDidLoad.我做错了什么?

cocoa-touch objective-c uiimageview uiimage ios

-3
推荐指数
1
解决办法
4982
查看次数