Simple
Just create a UITextView instance, populate with data, and show. Just a few issues to address
(a) we must watch out for the evil CR or is that CRLF issue so we have a helper method to
convert the NSString instance 'convertCRToCRLF'. This might not apply for what you are doing?

(b) To get auto-scrolling to work is a bit of a chore, this is if you have a cursor placement to work with, in this case it is 0.
A bug in iPhone OS 3.0 means we must supply a length, but beware of placing the cursor after the end since you get a range check if
the length is one.

	stringAsNSString := 'foo' asNSStringUTF8.
	stringAsNSStringConvertedCR := self convertCRToCRLF: stringAsNSString.
	stringAsNSString release.
	ObjectiveCBridge performSelectorOnMainThread: 
		[
		helpfulRange := NSRange location: 0 length: 0.
		stringAsNSStringConvertedCR length > 0 ifTrue: [helpfulRange length: 1].
		targetView setText: 	stringAsNSStringConvertedCR.
		targetView setSelectedRange: helpfulRange.
		targetView scrollRangeToVisible: helpfulRange.
		self sharedApplication delegate  
			rotateViewFrom: self transitionContainer view 
			toView: self prPageViewController view 
			animationDuration: 0.75 
			animationTransition: 2
			curve: 3
			cached: false asObjc.
		].
	"more stuff"
	
convertCRToCRLF: aNSString
	| cr crlf newString |
	cr := (Character cr) asString asNSStringUTF8.
	crlf := String crlf asNSStringUTF8.
	newString := aNSString stringByReplacingOccurrencesOfString: cr withString: crlf.
	cr release.
	crlf release.
	^newString.


The next trick is how do you indicate you are DONE? This is an exercise for the reader. For WikiServer we have a button bar and you tap Done.
OK there is a bit of magic here, we can't actually ask the UITextView instance for 'text' because it actually returns an autoreleased freed object.
So we have extended UITextView so that textRetained is return [self.text retain]

Now we execute the text := textView textRetained on the main thread, then we have to convert back from CRLF to CR in the NSString logic then convert the NSString back to a Smalltalk String. You could do the conversion in Smalltalk, likely you should run some tests to see which is faster.

	ObjectiveCBridge performSelectorOnMainThread: [text := textView textRetained]. 
	ourSmalltalkStringThenIs := (self convertCRLFToCR: text) asString
	text release.
	
convertCRLFToCR: aNSString
	| cr crlf newString |
	cr := (Character cr) asString asNSStringUTF8.
	crlf := String crlf asNSStringUTF8.
	newString := aNSString stringByReplacingOccurrencesOfString: crlf withString: cr.
	cr release.
	crlf release.
	^newString.

There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki