nsstring

Cocoa数据类型(NSString等)

雨燕双飞 提交于 2019-12-09 16:24:59
Cocoa框架中的数据类型 1 NSRange: typedef struct _NSRange{ unsigned int location; unsigned int length; }NSRange; location:表示范围的起始点 length:表示范围中所含元素的个数 作用: 用以表示相关事物的范围,如字符串中的字符范围或者是数组中元素的范围. 1.1 创建方式: 1.1.1 直接赋值 NSRnage range; range.location = 0; range.length = 4; 1.1.2 定义的同时进行初始化 NSRange range = {0,4}; 1.1.3 使用Cocoa提供的 API NSMakeRange();来创建: NSRange range = NSMakeRange(0,4); 使用NSMakeRange(location,length)来创建NSRange的好处是:可以在任何可以使用函数的地方使用它。 例如:[anObject flarbulateWithRange: NSMakeRange(0,4)]; 类似于C++中的anObject.flarbulateWithRange(NSMakeRange(0,4)); 2几何数据类型: typedef struct _NSPoint{ float x; float y;

iOS小技巧总结,绝对有你想要的

回眸只為那壹抹淺笑 提交于 2019-12-09 15:13:58
字数947 阅读2032 评论26 喜欢99 在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新。 UITableView的Group样式下顶部空白处理 //分组列表头部空白处理 UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.1)]; self.tableView.tableHeaderView = view; UITableView的plain样式下,取消区头停滞效果 - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat sectionHeaderHeight = sectionHead.height; if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView;.contentOffset.y>=0) { scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0); } else if(scrollView.contentOffset.y>=sectionHeaderHeight) { scrollView.contentInset

OC图书馆系统(含归解档)

▼魔方 西西 提交于 2019-12-09 13:25:26
OC图书馆系统 功能介绍: 1.图书馆内可以 添加 、 删除 书籍。 2.图书馆可以 查询 书籍的信息,包括书名、作者、书籍编号、书籍分类、书籍剩余可借阅量。 3.图书馆可以 打印 出总书单,还可以按照要求查询某一作者或某一类别的书单。 4.学生类可以在图书馆中借阅书籍,并可 计算借阅时间 (书籍的借出时间将归档在你电脑上的某个文件中,直至归还),超时将额外收费。 #import <Foundation/Foundation.h> 下面先从Book类开始: Book类建立: @interface: @interface Book : NSObject<NSCoding,NSCopying> @property(copy,nonatomic) NSString *bookName,*bookWriter,*bookPrice,*sort; @property int bookCode,bookCount; @property NSDate *borrowTime,*returnTime; @property NSString *strborrowtime; Book类属性包括NSString:书名、作者、价格及分类,int:书本编号、书本数量, NSDate:借出及归还时间,NSString:借出时间的string格式。这里不需要归还时间的string格式

How to read text file without knowing the encoding

社会主义新天地 提交于 2019-12-09 11:36:47
问题 When reading a text file that was created somewhere else outside my app, the encoding used is unknown. My app has being using NSUnicodeStringEncoding (which is the same as NSUTF16StringEncoding) so have problems reading other than UTF16 encoded files. Is there a way I can guess the encoding of a file? My priority is to be able to read UTF8 files and then all other files. Is iterating through available encodings and check if read string's length is more than zero is really a good approach?

Shuffling Letters in an NSString in Objective-C

送分小仙女□ 提交于 2019-12-09 11:33:21
问题 I have written this function which shuffles the contents of a NSString , and it seems to work, but every now and then it crashes. This may be a roundabout way, but I put the characters into an array, swap the elements in the array randomly, and then turn the array back into a string. I'm not sure what I am doing that is unsafe which makes it crash. I thought it was possibly that I am setting finalLettersString = result , but I also tried finalLettersString = [NSString stringWithString:result]

UITextField常用属性

二次信任 提交于 2019-12-09 10:48:38
UITextField是我们经常用的之一但是常用的属性都很熟悉,有些不常用的我也总结下,例如下面的: UIImageView * myView = [[ UIImageView alloc]initWithImage:[UIImage imageNamed:@"face.png"]]; UIImageView * myView2 = [[ UIImageView alloc]initWithImage:[UIImage imageNamed:@"face.png"]]; UITextField *myTextField=[[UITextField alloc]initWithFrame:CGRectMake(40, 40, 240, 60)]; //初始化一个UITextField的frame myTextField.textColor=[UIColor redColor]; //UITextField 的文字颜色 myTextField.delegate=self;//UITextField 代理方法设置 myTextField.placeholder=@"输入密码";//UITextField 的初始隐藏文字,当然这个文字的字体大小颜色都可以改,重写uitextfield,下次介绍 myTextField.textAlignment=UITextAlignmentCenter;

Passing data between view controllers - iOS Xcode - what's a good way?

前提是你 提交于 2019-12-09 08:21:26
Alright, I'll try and make this as simple as possible (I was seeming to get the run around on chat.stackoveflow.com when I tried asking this question). I want to pass the text from a textfield in one viewcontroller to another viewcontroller. Should I use a Model class and store the the textfield.text in a Model.[h/m] files and then have the second view controller access the data stored in the model? Basically this is what I have, ViewControllerWelcome.h @interface ViewControllerWelcome : UIViewController { } @property (weak, nonatomic) IBOutlet UITextField *textFieldUsername;

How can I convert a NSString representation of a time value into two NSInteger's containing the hour and minute?

左心房为你撑大大i 提交于 2019-12-09 01:45:43
问题 I'm diving into iOS development and the Objective C language and am building an alarm clock app to become familiar with the SDK and language. I have an NSString object that represents a time, with the range "1:00 am" to "12:59 am" . I need to convert this NSString into two NSInteger 's that contain the hour value and minute value. As I'm doing this, I'm finding the NSString manipulation that I'm doing to be extremely laborious and it just feels like sloppy code. Is there a simple way to

NSStream, UTF8String & NSString… Messy Conversion

和自甴很熟 提交于 2019-12-09 01:43:49
问题 I am constructing a data packet to be sent over NSStream to a server. I am trying to seperate two pieces of data with the a '§' (ascii code 167). This is the way the server is built, so I need to try to stay within those bounds... unichar asciiChar = 167; //yields @"§" [self setSepString:[NSString stringWithCharacters:&asciiChar length:1]]; sendData=[NSString stringWithFormat:@"USER User%@Pass", sepString]; NSLog(sendData); const uint8_t *rawString=(const uint8_t *)[sendData UTF8String];

Search for a string between two known strings

青春壹個敷衍的年華 提交于 2019-12-09 00:27:21
问题 I have a String with this content: href="http://www.website.com/" /> [...] [...] I just want to get the central part of the string. How is it possible to get the part between @"href="" and @"" />" Note: Even if it looks like xml-code, it is inside of a NSString. 回答1: I got it! This is the code (not very nice written): NSRange rr2 = [content rangeOfString:@"href=\""]; NSRange rr3 = [content rangeOfString:@"\" />"]; int lengt = rr3.location - rr2.location - rr2.length; int location = rr2