nsstring

iOS开发之自定义UITableViewCell

房东的猫 提交于 2019-12-26 19:09:00
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 等高的Cell 一、storyboard方式 创建一个继承自UITableViewCell的子类 在storyboard中 - 往cell里面增加需要用到的子控件 - 设置cell的重用标识 - 设置cell的class为我刚才创建的那个Cell类型XXDealCell 3. 在控制器中 - 利用重用标识找到cell - 给cell传递模型数据 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.deals.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"deal"; XXDealCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; //取出模型数据 cell.deal = self.deals[indexPath.row]; return cell; } 4

RetainCount is -1 after alloc? [duplicate]

拥有回忆 提交于 2019-12-25 18:39:02
问题 This question already has answers here : Calling -retainCount Considered Harmful (2 answers) Closed 6 years ago . Please don't mark Duplicate:- I have created the few lines NSString *str = [[NSString alloc] init]; str = @"Test"; NSLog(@"%d",[str retainCount]); and Output is -1 .Please explain. 回答1: It is a dupe of the question I pointed to. It is -1 because you are printing UINT_MAX as a signed integer. The RC is -1 because that is a singleton string generated by the compiler, effectively,

Convert NSData of Image from database to NSString in iPhone

☆樱花仙子☆ 提交于 2019-12-25 18:18:12
问题 I am converting NSData of Image from database to NSString in Iphone Here is my code imageData1 = [[NSData alloc] initWithBytes:sqlite3_column_blob(compiledStatement, 3) length: sqlite3_column_bytes(compiledStatement, 3)]; NSString * Str1 = [NSString base64StringFromData: imageData1 length: [imageData1 length]]; NSData *data1=[NSData base64DataFromString:Str1]; NSString* newStr1 = [[NSString alloc] initWithData:data1 encoding:NSUTF8StringEncoding]; the length of data is 6511 , but the newstr1

Should I retain NSString when it points to a literal?

匆匆过客 提交于 2019-12-25 18:14:18
问题 if (url_leng) { NSString *open_string; if (g_system_status.language_code == 0) open_string = @"Open"; else if (g_system_status.language_code == 1) open_string = @"Abrir"; [open_string retain]; [alert addButtonWithTitle : open_string]; g_scan_result = targ_url; } Consider the above code segment. My question is about the "retain" statement. Somehow I need the retain statement to make the code work. My only explanation is when open_string goes out of scope, a release call will be made against it

Objective-C: 字符串NSString与NSMutableString

孤街醉人 提交于 2019-12-25 14:06:45
字符串算是OC中非常重要和常用的一部分内容,OC中的字符串与我之前在学习C,C++,Java中的字符串有一定的不同,它非常类似于C++中容器的概念,但用法却与之还是有很大的不同,也许是因为OC的语法就与其他我们常用的编程语言不尽相同。 这里总结一下字符串NSString与NSMutableString。 一. NSString NSString代表字符序列不可变的字符串,NSString的功能非常强大,OC的字符串处理比C语言的饿字符串简单、易用得多。 这里我们通过一个具体的例子来进行分析。 创建两个字符串对象: NSString *str1 = @"this is string A"; NSString *str2 = @"this is string B"; 计算字符串中的 字符个数 : NSLog(@"Length of str1 : %lu" , [str1 length]); 利用 stringWithString 将一个字符串复制到另一个字符串: res = [NSString stringWithString : str1]; NSLog(@"copy : %@" , res); stringByAppendingString ,将一个字符串复制到另一个字符串的末尾: str2 = [str1 stringByAppendingString:str2];

Attempt to mutate immutable object error

梦想的初衷 提交于 2019-12-25 12:11:28
问题 My code crashes at this line: [(NSMutableString *)string replaceCharactersInRange:range withString:@""]; with the error attempt to mutate immutable object. How is this happening and how do i fix it? 回答1: The string isn't mutable, casting is not magic, it wouldn't turn it into a mutable string. You should do it on a mutable copy: NSMutableString* mutableString= [string mutableCopy]; [mutableString replaceCharactersInRange:range withString:@""]; 回答2: You are typecasting an immutable string and

Attempt to mutate immutable object error

一世执手 提交于 2019-12-25 12:10:05
问题 My code crashes at this line: [(NSMutableString *)string replaceCharactersInRange:range withString:@""]; with the error attempt to mutate immutable object. How is this happening and how do i fix it? 回答1: The string isn't mutable, casting is not magic, it wouldn't turn it into a mutable string. You should do it on a mutable copy: NSMutableString* mutableString= [string mutableCopy]; [mutableString replaceCharactersInRange:range withString:@""]; 回答2: You are typecasting an immutable string and

Equivalent for “stringByDeletingPathExtension ” for an array

我们两清 提交于 2019-12-25 12:05:25
问题 I want to run stringByDeletingPathExtension for all NSString members of an NSArray. How can I do this in Objective-C? 回答1: NSArray *myArray = ... ; [myArray makeObjectsPerformSelector:@selector(stringByDeletingPathExtension)]; EDIT : As @Wevah pointed out in the comments, this solution does not solve the problem, since stringByDeletingPathExtension returns a string rather than modified the object on which is invoked. NSMutableArray *newArray = [[[NSMutableArray alloc] initWithArray:myArray]

Rotating NSString in Swift

≡放荡痞女 提交于 2019-12-25 10:23:06
问题 I'm trying to do something like the attached image. I thought this page would lead to the answer http://www.informit.com/articles/article.aspx?p=2149190&seqNum=13 or Rotating a NSString in drawRect Drawing rotated text with NSString drawInRect but converting objC to swift is troublesome. I can easily draw my arrows but getting the NSString to rotate then translate is problematic. It does weird things like drawing off screen, wrong angles, etc. I've tried this and many variations

Rotating NSString in Swift

拈花ヽ惹草 提交于 2019-12-25 10:19:32
问题 I'm trying to do something like the attached image. I thought this page would lead to the answer http://www.informit.com/articles/article.aspx?p=2149190&seqNum=13 or Rotating a NSString in drawRect Drawing rotated text with NSString drawInRect but converting objC to swift is troublesome. I can easily draw my arrows but getting the NSString to rotate then translate is problematic. It does weird things like drawing off screen, wrong angles, etc. I've tried this and many variations