小编Nik*_*uhe的帖子

子视图删除并添加目标c/iphone

我有一个UIViewController类,我在其中创建一个UIView实例.然后我用25个子视图初始化(表示填充)它,每个子视图包含一个图像(1,2,...,25).然后在这些图像中点击5次后,我调用了一个我使用过的函数

for(UIView *subview in [contentView subviews]) {
    [subview removeFromSuperview];//ContentView name of my view
}
Run Code Online (Sandbox Code Playgroud)

删除以前添加的子视图.然后我使用相同的approch添加25个新的子视图(图像1,2,3,.... 25).但这次没有添加子视图.有人可以给我一些添加和删除子视图的完整代码.

我第一次添加子视图时使用了以下代码

//create main window

contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor blackColor];
self.view = contentView;
[contentView release];

//adding 25 subview 1st time
int a=0;
int b=0;
for (int i = 0; i < 26; i++)
{

    CGRect dragRect = CGRectMake(0.0f, 0.0f, x, y);
    dragRect.origin = CGPointMake(a,b);
    DragView *dragger = [[DragView alloc] initWithFrame:dragRect];
    NSString *Flower = [[NSArray arrayWithObjects:@"1.png", @"2.png", @"3.png",@"4.png", @"5.png", @"6.png",@"7.png",@"8.png", …
Run Code Online (Sandbox Code Playgroud)

objective-c

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

解码百分比转义了NSXMLParser委托方法中的字符串

我从服务器数据中获取UTF8编码数据就好Less%20than%20100但我需要这些数据Less than 100(解码格式),我的NSXMLParsing委托方法就像

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 
    attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"option"]) {

            dict = [[NSMutableDictionary alloc]init];
            [dict setValue:[attributeDict objectForKey:@"text"] forKey:@"text"];/* Here itself i need to decode & save in to my dict */
}
Run Code Online (Sandbox Code Playgroud)

如何解码这些数据.

escaping objective-c nsxmlparser ios

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

Objective C中的类对象

我来自Java到Objective C,类对象的想法让我想知道与Java的相似之处.从Apple文档中的Objective C指南:

类定义的信息被编译并记录在可用于运行时系统的数据结构中.编译器只创建一个对象,即一个类对象,以表示该类.

所以我的理解是类对象是为程序使用的所有类创建的,而类对象是用于为该类创建对象的类.

为了比较,JVM是否为它加载的所有类都有类似的对象?

java objective-c

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

无法在较低版本的xcode中运行Xcode 5中内置的应用程序

我安装了Xcode 4.6.3的Mac版本10.7.5.我有一个用Xcode 5构建的应用程序,这个项目在我早期的Xcode安装中没有打开.它告诉我一个错误的说法

无法打开文档"Main.Storyboard".无法读取存档.请使用较新版本的Xcode.请考虑更改文档的开发目标以保持兼容性.

为什么我无法使用My Xcode运行此应用程序.

macos xcode

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

insertObject:atIndex:overObjectObjectItIndex:withObject:on NSMutableArray的好处是什么

当使用NSMutableArray中的新值替换某个索引处的值时,旧值将保留在内存中.修复的方法是在每个循环之前初始化一个新的NSMutableArray.

重现步骤:

- (id) init{
    self.overlays = [[NSMutableArray alloc] initWithCapacity: [self.anotherArray count]];
}

- (void) someOtherMethod{
    for(int i = 0 ; i < self.anotherArray ; i++){
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
        [view setBackgroundColor:[UIColor colorWithRed:0 
                                                green:0 
                                                 blue:0 
                                                alpha:1]];
        [view setAlpha: .2];
        [self.overlays insertObject:view atIndex: i]
    }
}

- (void) main{
    for(int i = 0 ; i < 4 ; i++){
        [myObject someOtherMethod];
    }
}
Run Code Online (Sandbox Code Playgroud)

insertObject:atIndex有效地导致内存泄漏,因为它不会释放该索引处的数组中的旧值.

我提交了一份错误报告,Apple回答说:

insertObject:atIndex:表现为已定义.它正在插入,而不是替代.如果要替换,则应使用-replaceObjectAtIndex:withObject:

insertObject:atIndex:怎么可能有任何好处,因为你总是丢失对该索引的旧对象的引用.

这是否只是为了避免修复问题,因为它符合旧的文档定义?

cocoa objective-c nsmutablearray automatic-ref-counting

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