c语言剖析oc的rangeofstring方法

在OC中,我们选择- (NSRange)rangeOfString:方法来判断字符串是否存在。该方法返回的是一个NSRange 类型的结构体,成员变量包括location、length。
需要注意的是:当这个字符串不存在时,返回的location不仅仅是NSNotFound,并且length的值也是0.

1
2
3
4
5
6
7
8
9
10
11
12
13
#import "WRReviewViewController.h"
@implementation
- (void)gotoDetail {
WRBookDetailViewController *detailVC = [[WRBookDetailViewController alloc] initWithBookId:self.bookId];
[self.navigationController.pushViewController:detailVC animated:YES];
}
- (void)gotoReview {
WRReviewViewController *reviewVC = [[WRReviewViewController alloc] initWithBookId:self.bookId reviewType:1];
[self.navigationController.pushViewController:reviewVC animated:YES];
}
@end