kullanın Ben birini almak ya da hücrede görünümünün diğer tip, sadece tableView:cellForRowAtIndexPath:
yönteminden iki farklı UITableViewCell
s döndürebilir amacıyla böylece regexes, URL'ler tespit etmek aşina sanırım.
O (fark lütfen, test tarayıcıda yazdığınız) aşağıdaki gibi görünebilir:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *dataString = // Get your string from the data model
// Simple pattern found here: http://regexlib.com/Search.aspx?k=URL
NSString *URLpattern = @"^http\\://[a-zA-Z0-9\-\.]+\\.[a-zA-Z]{2,3}(/\\S*)?$";
NSError *error = NULL;
NSRegularExpression *URLregex = [NSRegularExpression regularExpressionWithPattern:URLpattern
options:NSRegularExpressionCaseInsensitive
error: &error];
NSUInteger numberOfMatches = [URLregex numberOfMatchesInString:string
options:0
range:NSMakeRange(0, [string length])];
if (numberOfMatches == 0) {
static NSString *PlainCellIdentifier = @"PlainCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
}
cell.textLabel.text = timeZoneWrapper.localeName;
}
else {
static NSString *FancyCellIdentifier = @"FancyCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
}
// Configure cell view with text view here
}
return cell;
}
Eğer varsa, NSString'de 'http' olup olmadığını kontrol edebilirsiniz. – rishi
@rishi, sorun çok sayıda url var, UITextView hepsini algılar gibi görünüyor, bu yüzden google.com, www.google.com, ... –